C++ :: Modify Element In Node Of Linked List With Value Assignment
Sep 7, 2014
I tried to modify staff name with an assignment value of other string but couldn't work it out. I managed to modify it by key in cin >>.
The purpose is that I want to assign string value from other different class to Staff class. An error : no match for 'operator=' in '* updateName = newStaffName' and note: no known conversion for argument 1 from 'std::string {aka std::basic_string<char>}' to 'const Staff&' occurred.
#include <iostream>
using namespace std;
class Staff {
friend ostream& operator << (ostream& os, Staff& m) {
os << "[" << m.ID << ", " << m.fName << "]";
[Code]...
View 3 Replies
ADVERTISEMENT
Sep 6, 2014
I'm trying to calculate the total price of books contained in a linked list. I've tried getTotal() function in linked list but error: no match for 'operator+=' in 'total += ptr->Node<Book>::info'| occurred. How can I access the price in the node and then calculate the total price.
Here is part of my code :
Book class
class Book {
protected :
int id;
string title;
double price;
string bookStatus;
[code]....
View 2 Replies
View Related
Mar 10, 2014
So I have linked list and function which deletes element if next element is bigger, so my code is working but its not working with first element, in the comment I have wrote code which I would code for checking that first element, but when ever I check it is blowing up all program.
#include <iostream>
using namespace std;
struct llist {
int x;
llist *next;
[Code] .....
View 1 Replies
View Related
May 27, 2013
I have made a Student record system in c++ using the concept of linked list. The program will take the student id, name and marks for 3 different exams. Then it will calculate the aggregate percentage based on those exams marks and display the relevant message according to the aggregate percentage. All is going well. But there is only one problem. When I modify the student record especially the marks, it doesn't change the aggregate percentage of that specific record. It shows the old one. Similarly the relevant message doesn't change too.
Code:
struct student{
int id;
char name[MAX];
string status;
double aggr;
int matric_marks, inter_marks, entryTest_marks;
[Code] .....
View 3 Replies
View Related
Apr 14, 2014
I'm having a problem trying to modify my patient's data. It seems to work, but once the block of code ends it does not save to the linked list.
Problem located in case M.
linked list template header: [URL] ...
patient header: [URL] ...
patient implementation: [URL] ...
#include <iostream>
#include "listTemplate.h"
#include "PatientRecord.h"
using namespace std;
char menu() {
char input
[Code]...
View 1 Replies
View Related
Oct 24, 2013
You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null.
The permute class uses a Note class as link list note to link all letters arrangement. The permute class has Note pointers, firstNote and lastNote, to point to the beginning and ending Notes of the link list as private data members. There are three other private data members (total, firstString and secondString) to store the total possible number of arrangements and strings pass into the class.
Write a driver to test the permute class to pass in any two strings of any sizes.
Other than mention in the following, you can add more classes, functions, and private data members to this program.
Note class
The Note class needs to have two private data members and a constructor. The two private data members are data and p pointer. The data’s data type is string and p pointer is Note. The Note class constructor has two parameters, one is string and the other is Note pointer.
Permute class
The Permute class has five private data members (*firstNote, *lastNote, total, firstString and secondString). The firstNote and lastNote pointers are point to Note. The total has integer data type. The firstString and secondString have string data type.
There should have at least three public member functions, Permute, permutation and print. The Permute function is the constructor which takes strings to initialize the private data members. The permutation function does the recursive call to arrange the strings and setup the link list. The print function will print out the private data member information.
Driver file
The driver file should declare a Permute eight elements pointer array. Instantiate eight Permute object with the following eight set of data and assign the object to the pointer array. Use a repetition to call the object’s print function to print out the private data member information. If the total of the permute private data member is less than 100 then print out the permutated letters four in a row, otherwise print out 9 in a row.
first = "", second="",
first = "", second ="CATMAN",
first = "C", second ="ATMAN",
first = "CA", second ="TMAN",
first = "CAT", second ="MAN",
first = "CATM", second ="AN",
first = "CATMA", second ="N",
first 1 = "CATMAN", second ="";
View 19 Replies
View Related
Dec 31, 2014
Code:
// Write a function called insertEntry() to insert a new entry into a linked list.
Have the procedure take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in this chapter), and a pointer to an element in the list after which the new entry is to be inserted.
// The function dveloped in exercise 2 only inserts an element after an existing element in the list, thereby prenting you from inserting a new entry at the front of the list.
(Hint: Think about setting up a special structure to point to the beginning of the list.)
#include <stdio.h
struct entry1 {
int value;
struct entry1 *next;
};
[code]...
This is a working version of the exercise, but I don't think I'm doing what's asked. I was able to add an element to the beginning of the list using an if statement, not creating a special structure that points to the beginning of the list. How would I go about creating a special structure that points to the beginning of the list to add a new element at the beginning of the list?
View 8 Replies
View Related
Dec 5, 2014
I create A program that will Add and Display the Link List but I have problem on it. If I add it will inserted in the prev node not in the next node. Here's my source code.
#include <stdio.h>
typedef struct Member {
int id;
char name[256];
struct Member *next;
[Code] ....
View 2 Replies
View Related
Apr 19, 2013
I have a struct with some select student information. My wish is to be able to have the user type in a surname from the list, and for that entry to be deleted. However I am slipping up for some reason.
Here is the start of my program showing my struct:
Code:
#include <stdio.h>
#include <string.h>
#define NAME_LEN 30
#define LINE_LEN 80
struct record {
[Code] ....
I get the following errors in my while loop as well as the if statement below that loop:
-invalid operands to binary !=
-invalid type of argument '->'
View 7 Replies
View Related
May 17, 2014
This is what I have at the moment which works as I would like but wondering if there is a better way of handling? Currently just making sure I know linked-lists well enough.
Code:
void push_to_end( node_t * headRef, int val ) {
node_t * tail = headRef;
node_t * new_node = malloc( sizeof ( node_t ));
while( headRef != NULL ) {
[Code].....
View 12 Replies
View Related
Aug 12, 2013
I'm trying to impliment a simple singly linked list, then allow a user to add a new node. I have mocked up a siimple example to illustrate my point using Linked Lists...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int x;
struct node *next;
[Code] ....
So I have done things similatr to this in C# and Java but not in C. There maybe some parts of this I'm sure some will disagree with in terms of buffers,overflow etc. but it's just the linked list part that I am interested in at the moment, I am only doing it like this because when it works, I will be extracting the working linked list stuff into another program that can deal with its I/O etc.
I have tried to comment as best I can to demonstarte my intentions and understandings per line of code. The add function needs to add a node of value x that the user has input, and add that to the end of the list - I'm sure that the print function is not doing all its supposed to do...
View 4 Replies
View Related
Mar 2, 2013
If p is a pointer pointing a node to be deleted, then what's wrong in the following code:
cout << "Do you want to delete this record? (y/n) ";
if (getch() == 'y' || getch() == 'Y'){// Delete record.
if (p == *ph){//If first node is to be deleted.
*ph = (*ph)->next;
delete p;
[Code] .....
View 2 Replies
View Related
Feb 27, 2015
I have to write a program which has the user be able to enter a specific value at a specific position of the linkedlist, replacing that node with the user defined value
EX: Enter the value 5 at 2nd node, which will override the old value at the 2nd node with the new one
I am getting a compiler error which terminates my program right after the user presses the return key after he/she has given a position to change the value
Error: Unhandled exception at 0x013C50C1 in Linked(1).exe: 0xC0000005: Access violation reading location 0x0000812B.
I am not going to show the whole code as the problem resides solely on the insert function:
void TheNode::insert(double num, int choice) {
int post = 0;
MyNode *ptr = new MyNode;
(*ptr).value = num;
MyNode *previous = head;
MyNode *current = head->next;
[Code] .....
View 1 Replies
View Related
Jan 27, 2013
I have a function that append node to a linked list like this:
struct ListNode{
int value;
struct ListNode* next;
};
void appendNode(struct ListNode* head, int num){
[code] ....
when I use it, the head in main() does not change its address and it's still pointing to NULL. Why??
View 5 Replies
View Related
Jul 10, 2014
Still toying with my self-coded linked list class and now another question: should I delete each node of my class with the delete in the class destructor or is it done automatically when the main() function ends?
View 4 Replies
View Related
Oct 24, 2014
How to remove node from linked list. I am trying to implement this in a file record to remove data from struct..I dont know how addressing in linked list work for structs;
#include <iostream>
#include<fstream>
#include<cstring>
#include<cstdlib>
using namespace std;
struct node{
int val;
[Code] ....
segmentation fault
View 11 Replies
View Related
Oct 25, 2013
I have a problem with inserting a node between two nodes.
Code:
#include <stdio.h>
#include <stdlib.h>
struct listelem {
int nbr;
struct listelem *next;
[Code] ....
View 8 Replies
View Related
Mar 6, 2015
I am having trouble adding a second node to a doubly linked list. I define my list as follows:
Code:
typedef struct Node {
char command[256];
int length;
struct Node *prev;
struct Node *next;
} userInput;
}
[code]...
Now, when I iterate back through my list (I want to start at the tail and work my way towards the head), I can only ever get the 1st node to print, then the 2nd node is garbage, which means, to me, that I've linked something wrong.
View 3 Replies
View Related
Aug 30, 2013
While I know that linked lists seem to be a fairly common problem area among beginner C programmers, most examples that I have come across abstract the sorting of a linked list to a separate function which is sadly not what I am trying to do.
The code below is my attempt to have the nodes inserted into their correct place so that once all nodes have been inserted they are already in a sorted order.
Code:
int main(int argc, char *argv[])
{
struct node_t* dict_head;
struct node_t* traversor;
struct node_t* newnode;
int list_size = 0, insert_key, search_key, delete_key, x;
char insert_word[WORDLEN];
/*Opening the dictionary file provided by the command line argument */
FILE *fp;
fp = fopen(argv[1], "r");
[Code]....
The problem is as follows. When you provide it with input in which the first word scanned is any other word than that which would be placed at the front of the list, it works as intended. For example.
7 world
0 ant
3 kodak
1 best
6 the
2 is
Produces ant -> best->is->kodak->best->world
However, swapping ant and world in the above input gives:
world->best->is->kodak->best->world
In regards to why I have my head node set as a node without a word or a key, it was suggested that I make it so that the first node inserted is set to be the head of the list and then changed as sorting required, yet this caused only additional problems.
View 10 Replies
View Related
Oct 18, 2014
I was trying to write a function in C to delete a node(only from the middle) from a Singly Linked List. I wrote one but not sure if the code will work fine under all test conditions. I have tested it and shows no error so far.
Code:
void deleteAt(struct node *root, int number){
while(root->link != NULL) {
if(root->link->item == number) //checks if the next node is the element to be deleted {
root->link = root->link->link; //points the link of the element to be deleted to the element before the element to be deleted
}
else
root = root->link;
} }
Or is there a better way to do this?
View 3 Replies
View Related
Sep 19, 2013
I need to delete the Nth node from a doubly linked list. I know I just cant delete it out right. I have all the goodies including a templetized node class. This is the code we're given:
template <typename T>
void doublyLinkedList<T>::deleteKthElement(const int item) {
}
It accepts an int, and should go to the Nth node and delete it.
View 1 Replies
View Related
May 1, 2013
I am trying to delete a node from the end of a Linked List but I have some problems. Every node has it's unique code. Here is what I do:
1. Ask the user for the unique code of the node.
2. Ask him if he wants to change the data in it or delete the whole node.
3. If he chooses to delete it, I do this:
//let's say that temp1 points to the node
List *temp2 = temp1;
temp1 = temp1->next;
delete temp2;
And it's just not deleting the node.
View 2 Replies
View Related
Oct 17, 2014
i am trying to develop a doubly linked list class. I became stuck at a few of the functions as well as the main.cpp file. i have to insert a character sentence "TRICK OR TREAT" spaces included. I am stuck on the display and the listsize functions and im unsure if my insert has the head node in it. The function parameters were given to us and most of this code was given from a single linked list.
//node.h
#pragma once
class Node
{
publi
[Code].....
View 1 Replies
View Related
Sep 8, 2014
I would like my function to return the data that was deleted. I have this code at the moment, where value_type is just an alias for int at the moment:
node::value_type linkedlist::removeFromHead(){
node* temp_head;
node::value_type data;
data = head_ptr->getData();
[Code] .....
When I try to use this function though, I get a segfault.
View 19 Replies
View Related
Mar 26, 2014
I am studying this sample code for linked list class node implementation. I am not 100% sure how this code keeps track of the head node. Here's what I know so far, and if you want to add/correct anything feel free to do so:
class Node {
public:
Node(); // constructor of class node without arguments
Node(int, Node*); //constructor with arguments of int type and a pointer node type
Node* next() const;
void setNext(Node*); //member fun, returning a pointer of node type
void setKey(int);
[Code] ......
View 8 Replies
View Related
Nov 30, 2014
Why is it sufficient to only have a pointer to the last node of a doubly linked list?
View 1 Replies
View Related