Question

1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum,...

1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum, courseName, & grade)

2) Change the type for the 'data' member variable in the node struct to CourseInfo (see #1) and rename it to 'courseData'

3) Modify the createNode function to receive a CourseInfo struct as a parameter. It should also display the address of the new node that is created. Display the address in both hex and decimal form.

4) Modify the display function to display the address of each node that is currently in the list. It should also display the course info data stored in the current node as well as the address of the next node in the list. Display the addresses in both hex and decimal form.

5) Modify the insertStart function to receive a CourseInfo struct as a parameter. It should also display the address of the new node that is inserted. Display the address in both hex and decimal form.

6) Comment out the following functions for now: insertPosition, deleteFirst, deleteLast, deletePosition

7) Create a function called getCourseInfo to get the course info data from the user. It should return a CourseInfo struct type that can be passed into both the createNode and insertStart functions

--------------------------------------------------------------------------------------------------------------------------------------------

#include

using namespace std;

struct node

{

CourseInfo courseData;

node *next;

};

struct CourseInfo

{

int courseNum;

string courseName;

char grade;

};

class list

{

private:

node *head, *tail;

public:

list()

{

head=NULL;

tail=NULL;

}

void createNode(int value)

{

node *temp=new node;

temp->data=value;

temp->next=NULL;

if(head==NULL)

{

head=temp;

tail=temp;

temp=NULL;

}

else

{

tail->next=temp;

tail=temp;

}

}

void display()

{

node *temp=new node;

temp=head;

while(temp!=NULL)

{

cout<data<<"\t";

temp=temp->next;

}

}

void insertStart(int value)

{

node *temp=new node;

temp->data=value;

temp->next=head;

head=temp;

}

void insertPosition(int pos, int value)

{

node *pre=new node;

node *cur=new node;

node *temp=new node;

cur=head;

for(int i=1;i

{

pre=cur;

cur=cur->next;

}

temp->data=value;

pre->next=temp;

temp->next=cur;

}

void deleteFirst()

{

node *temp=new node;

temp=head;

head=head->next;

delete temp;

}

void deleteLast()

{

node *current=new node;

node *previous=new node;

current=head;

while(current->next!=NULL)

{

previous=current;

current=current->next;

}

tail=previous;

previous->next=NULL;

delete current;

}

void deletePosition(int pos)

{

node *current=new node;

node *previous=new node;

current=head;

for(int i=1;i

{

previous=current;

current=current->next;

}

previous->next=current->next;

}

};

int main()

{

list obj;

obj.createNode(25);

obj.createNode(50);

obj.createNode(90);

obj.createNode(40);

cout<<"\n--------------------------------------------------\n";

cout<<"---------------Displaying All nodes---------------";

cout<<"\n--------------------------------------------------\n";

obj.display();

cout<<"\n--------------------------------------------------\n";

cout<<"-----------------Inserting At End-----------------";

cout<<"\n--------------------------------------------------\n";

obj.createNode(55);

obj.display();

cout<<"\n--------------------------------------------------\n";

cout<<"----------------Inserting At Start----------------";

cout<<"\n--------------------------------------------------\n";

obj.insertStart(50);

obj.display();

cout<<"\n--------------------------------------------------\n";

cout<<"-------------Inserting At Particular--------------";

cout<<"\n--------------------------------------------------\n";

obj.insertPosition(5,60);

obj.display();

cout<<"\n--------------------------------------------------\n";

cout<<"----------------Deleting At Start-----------------";

cout<<"\n--------------------------------------------------\n";

obj.deleteFirst();

obj.display();

cout<<"\n--------------------------------------------------\n";

cout<<"-----------------Deleting At End-------------------";

cout<<"\n--------------------------------------------------\n";

obj.deleteLast();

obj.display();

cout<<"\n--------------------------------------------------\n";

cout<<"--------------Deleting At Particular--------------";

cout<<"\n--------------------------------------------------\n";

obj.deletePosition(4);

obj.display();

cout<<"\n--------------------------------------------------\n";

system("pause");

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
class list
{
private:
node *head, *tail;
public:
list()
{
head=NULL;
tail=NULL;
}
void createnode(int value)
{
node *temp=new node;
temp->data=value;
temp->next=NULL;
if(head==NULL)
{
head=temp;
tail=temp;
temp=NULL;
}
else
{
tail->next=temp;
tail=temp;
}
}
void display()
{
node *temp=new node;
temp=head;
while(temp!=NULL)
{
cout<<temp->data<<"\t";
temp=temp->next;
}
}
void insert_start(int value)
{
node *temp=new node;
temp->data=value;
temp->next=head;
head=temp;
}
void insert_position(int pos, int value)
{
node *pre=new node;
node *cur=new node;
node *temp=new node;
cur=head;
for(int i=1;i<pos;i++)
{
pre=cur;
cur=cur->next;
}
temp->data=value;
pre->next=temp;
temp->next=cur;
}
void delete_first()
{
node *temp=new node;
temp=head;
head=head->next;
delete temp;
}
void delete_last()
{
node *current=new node;
node *previous=new node;
current=head;
while(current->next!=NULL)
{
previous=current;
current=current->next;
}
tail=previous;
previous->next=NULL;
delete current;
}
void delete_position(int pos)
{
node *current=new node;
node *previous=new node;
current=head;
for(int i=1;i<pos;i++)
{
previous=current;
current=current->next;
}
previous->next=current->next;
}
};
int main()
{
list obj;
obj.createnode(25);
obj.createnode(50);
obj.createnode(90);
obj.createnode(40);
cout<<"\n--------------------------------------------------\n";
cout<<"---------------Displaying All nodes---------------";
cout<<"\n--------------------------------------------------\n";
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"-----------------Inserting At End-----------------";
cout<<"\n--------------------------------------------------\n";
obj.createnode(55);
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"----------------Inserting At Start----------------";
cout<<"\n--------------------------------------------------\n";
obj.insert_start(50);
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"-------------Inserting At Particular--------------";
cout<<"\n--------------------------------------------------\n";
obj.insert_position(5,60);
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"----------------Deleting At Start-----------------";
cout<<"\n--------------------------------------------------\n";
obj.delete_first();
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"-----------------Deleing At End-------------------";
cout<<"\n--------------------------------------------------\n";
obj.delete_last();
obj.display();
cout<<"\n--------------------------------------------------\n";
cout<<"--------------Deleting At Particular--------------";
cout<<"\n--------------------------------------------------\n";
obj.delete_position(4);
obj.display();
cout<<"\n--------------------------------------------------\n";
system("pause");
return 0;
}
Add a comment
Know the answer?
Add Answer to:
1) Create a struct called CourseInfo to store info about a course (Include variables for courseNum,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • need this updated so it will delete the list and then recreate it again /***********************************************************/ /*...

    need this updated so it will delete the list and then recreate it again /***********************************************************/ /* Header files. */ /***********************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> /***********************************************************/ /* Structure definitions. */ /***********************************************************/ struct node { int data; struct node *right; struct node *left; }; struct trash { struct node *node; struct trash *next; }; /****************************************/ /* BUILD_LIST. */ /****************************************/ void BUILD_LIST(int number2Add, struct node *(*head), struct node *(*tail)) { int i; struct node *previous, *current; *head = NULL; *tail =...

  • Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include...

    Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list */ void...

  • Please rewrite this function using recursive function #include using namespace std; struct Node { char ch;...

    Please rewrite this function using recursive function #include using namespace std; struct Node { char ch; Node* next; }; class LinkedList { Node* head; public: LinkedList(); ~LinkedList(); void add(char ch); bool find(char ch); bool del(char ch); friend std::ostream& operator<<(std::ostream& out, LinkedList& list); }; LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { Node* cur = head, * tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void LinkedList::add(char ch) { Node* cur = head,...

  • #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ...

    #include <iostream> using namespace std; struct ListNode { float value; ListNode *next; }; ListNode *head; class LinkedList { public: int insertNode(float num); void deleteNode(float num); void destroyList(); void displayList(); LinkedList(void) {head = NULL;} ~LinkedList(void) {destroyList();} }; int LinkedList::insertNode(float num) { struct ListNode *newNode, *nodePtr = head, *prevNodePtr = NULL; newNode = new ListNode; if(newNode == NULL) { cout << "Error allocating memory for new list member!\n"; return 1; } newNode->value = num; newNode->next = NULL; if(head==NULL) { cout << "List...

  • I have a C++ code that lets me enter, display and delete a student record. I...

    I have a C++ code that lets me enter, display and delete a student record. I need to implement a function that prints the average grade score of the students I input. Below is my code and a picture of how my code looks right now. #include<iostream> #include<stdlib.h> using namespace std; //Node Declaration struct node {    string name;    string id;    int score;    node *next;   }; //List class class list {        private:        //head...

  • In def c++ IDE correct mistake and screenshot output ------------------------------------------------------------------------------ #define NULL 0 #include <iostream> /*...

    In def c++ IDE correct mistake and screenshot output ------------------------------------------------------------------------------ #define NULL 0 #include <iostream> /* Name: Rabia Saad Al-wethnani ID: 43503535 Section: 2486 */ using namespace std; struct Node { int item; //data Node *next; //pointer to the next node in the list }; Node* createNode(int); int isPresent(Node*, int); void appendNode(Node*&, int); void displayList(Node*); void printLists(Node*, Node*); void swapNodes(Node* &head, int s); void findIntersection(Node* first, Node* P); void findUnion(Node* first, Node* P); int main() { Node* L = NULL,...

  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

  • c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream>...

    c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream> using namespace std; template<class T> struct Node {     T data;//data field     Node * next;//link field     Node(T data) {       this->data = data;     } }; template<class T> class linked_list{ private:       Node<T> *head,*current; public:       linked_list(){//constructor, empty linked list         head = NULL;         current = NULL;       }       ~linked_list(){         current = head;         while(current != NULL) {          ...

  • Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual...

    Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual studio 2013 this is my code so far #include <cstdlib> #include <list> #include <iostream> using namespace std; struct node {    int data;    node* next; }; void initialize(node*p); void insert(int data,int n); void remove(int b,int pos); bool empty(node*); void length(); bool valuein(int c); int reportvalue(int value); void ptintlist(); int menu(); int main() {    struct node*head=NULL;    char commands;    int value;   ...

  • For the LinkedList class, create a getter and setter for the private member 'name', constructing your...

    For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT