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;
Compiles with 0 error but on running 2 Errors appear.
I'm Inputting data of an object from user and then inserting it in the link list.
#include <iostream> //#include <fstream> using namespace std; #define LEN 100 //////////////////////////////////////////////////////////////////////////////////////////////////// class employee{
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 << "]";
I've been trying to read a .txt into a linked list in the attached code. I'm running into problems, specifically I'm getting errors on line 41 (curr->word=charTemp. I'm trying to set the word array equal to the charTemp array. I've tried strcpy with no luck .
Code:
#include <stdio.h>#include <stdlib.h> #include <string.h> //Struct for linked list typedef struct node { char word[25]; struct node *next; } node;
I am trying this without a head/start pointer which would generally hold the address of first node. I have 3 nodes here from which I am trying to delete last node, but its not happening. I might be wrong in my logic and this is my first linked list program.
add of p1::0x9605008 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::(nil) add of p1->next::0x9605018 add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)
no of nodes 3
enter the addresss of node to delete it 0x9605028
after deletion attempted
add of p1::0x9605028 add of p2::0x9605018 add of p3::0x9605028 add of p1->prev::0x9605018 add of p1->next::(nil) add of p2->prev::0x9605008 add of p2->next::0x9605028 add of p3->prev::0x9605018 add of p3->next::(nil)
no of nodes 3
In this example i am trying to delete the node 3 which is p3, by deleting its address 0x9605028. But after deletion the node count is still 3 and addresses are like unexpected!
I have a standard linked list in template format (with T being the typename) with the following relevant insertion operators:
bool PushFront (const T& t); // Insert t at front of list bool PushBack (const T& t); // Insert t at back of list
I want to build a list of pointers to objects (we'll call them objects of class Box for simplicity) that is member data for a parent class (we'll call that class Warehouse). However, I want to have a constant Box....const Box INVISIBLE_BOX = Box(); that represents a nonexistent Box. However, I cannot use either
PushFront(&INVISIBLE_BOX) or PushBack(&INVISIBLE_BOX)
to add INVISIBLE_BOX to the list of boxes without getting an invalid conversion error invalid conversion from âconst warehouse::Box*â to âwarehouse:: Box*â [-fpermissive]
What can I do to make it take a constant Box? I am using g++ to compile these files.
I am wanting to be able to add as many different instances of data, while the user has not stated 'n', but then it only ever writes back to the screen the input for the last set of data. Where as I want to display back to the screen all the data that has been entered.
class MyOwner { ... int m_count; bool b_locked; };
[Code] ....
I am using an API where I create many MyObjects on the heap, and the API uses a separate thread to send messages to each object. Each MyObject contains a pointer to MyOwner.
Suppose I want to keep a count of all messages received in all MyObjects: How can I do this in a thread safe way?
I am assuming that the code I have written above will not be safe--at the very least it seems that it would potentially miss message counts when it was locked--not the worse case scenario for me. I am most concerned about not causing the application to crash.
The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.
When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges). what I am doing incorrect?
// CSCI 3300
#include <cstdio> using namespace std; struct ListCell { ListCell* next; int vertex; double weight; ListCell(int v, double w, ListCell* nxt)
I need an explanation of what linked lists are. How the nodes are been defined and used, especially in an object oriented programming. With a code example.
111111111 Lisa Porter 3 ENEE 114 CMSC 412 ENME 515 333333333 Alex Simpson 1 CMSC 412 ***
In the form student ID and then first name last name number of courses and finally the course code(s). Im currently attempting to read these into linked lists with the following code:
#include<stdio.h> #include<string.h> #include<stdlib.h> struct CourseInfo { int courseID; char courseName[30];
[Code] ......
I get no errors or warnings however when i print this out i get:
111111111 Lisa
Lisa Porter 3 ENEE 114 CMSC 412 ENME 515
And then the program crashes. So i know that for some reason the problem is the
fgets(rootPtr->FirstName, 22, p);
But I do not know why because it seems to work for the other fgets. I also want to know why the while loop never runs and it crashes instead.
If there is a creation of a list, how can one find the sizeof the list. and is it possible to copy all the data from the linked list into an array. Assuming that the data is of type
I'm trying to run so called student-administration program.I got functions that can read and write student data, but the one saving the data from about 30 students has some problem that I can't figure. (warning: I'm quite new to C programming)so this is the code:..I guess I can't use global variables as function arguments?
The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.
When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges).
#include <cstdio> using namespace std; struct ListCell { ListCell* next; int vertex; double weight; ListCell(int v, double w, ListCell* nxt)
why strcmp() doesn't return true when comparing a string constant with a string that was acquired via a linked list. By the way, the data in the linked list was taken from a text file. Does that imply that there's a new line () character in the string from the linked list?
I have been attempting to store mathematical functions in a file by parsing them into a linked list with a variable sized char ** array as my storage device. I have ran into problems with the memory management detail. The program crashes before output is flushed to the console, so printf() wasn't a debugging option. Neither is my actual debugger, since it seems to get a SIGTRAP every time. I have my warnings turned all the way up, but no errors or warnings are appearing. The part I know works is the actual code that opens the file and gets a line from the file. As far as the two functions that implement the linked list, that is most likely where the problem lies. My current attempt is basically to store the size of the dynamic array in the structure and keep resizing it until there are no more tokens. Then I will store the number of elements of the array in the structure and move on to the next node.
i am making a program that reads a file from .txt and print them out using linked list. However, i need to sort them from the highest price to lowest price.
Code:
/* my structs */ typedef struct{ Node *head; Node *tail; Node *iterator; int size; } List;
[Code]...
i know its long but im afraid that i might miss out some things.
The program use a circular linked list and data structures to store the tasks.
- Every task should include a task name, a name for the person assigned to it, and the deadline for the task. - Variables should be dynamic and their sizes should be determined at runtime based on the length of user input. - You should implement the following functions (with appropriate arguments and return types) for your structure: add(), remove(), search(), and list(). - The add()function should add tasks alphabetically by task name. You do not need to implement any file operations. - The search() function should be able search for a task by the task assignee name or the task name. - The list() function should print records to the screen in the order they appear in the circular linked list. - You should successfully deallocate all of the allocated memory before termination of your program.
In the program I'm writing, I'm creating a linked list of students with individual data read from a file. At the moment, I have written two functions to accomplish this; one that creates a student node and fills it from a line file, and a second that calls on the first to create a linked list. It seems to work fine except for one thing; It seems that EOF is being reached first, but the function continues on anyways? Here is my code so far...
I'm trying to make a program that reads data from a text document and allows me to modify it. I am stuck with the display() function. I can get the printf statement to display all my array values except the char AD value. When I include flight[i].AD it causes the program to crash. When I run the program to only display the AD variable I get a bunch of weird symbols. I'm not sure where the program is going wrong because it seems to be storing values properly except for the AD variable.
#include <fstream> using namespace std; //named constants const int MAX=100; //maximum flights const int SIZE=20; //maximum characters //struct definition struct FlightType { char name[SIZE];
I'm unable to access private variables belonging to the object class Date, which my overloaded >> operator is a friend of. I can't see anything in my code that would be causing this error. The .h file and the definition of the problematic overloaded operator from the implementation file are below:
#ifndef DATE_H #define DATE_H #include <string> using namespace std; class Date { public: // Initializes a date to the default value of January 1, 1970.
[Code] .....
The error message states that the vars (month, day, year) are declared as private in the header file and then a reference is made to the lines where I attempt to access these in the .cpp file and it reads: "in this context".
I'm trying to write a function that takes two linked lists and creates a third one with only the common elements.
It assumes the first list (the caller) has no dups, but it doesn't seem to be working. The program doesn't crash, it just hangs when it is supposed to display L3 (the third list)..everything else runs and is displayed fine.