Question

In: Computer Science

1) a. Write down a C++ program which will create a list (simple linear linked list)...

1) a. Write down a C++ program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a gradepoint average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function you wrote (by printing student’s information on screen).

b. Write the psudecode for the program

Solutions

Expert Solution

PLEASE GIVE THUMBS UP, THANKS

input data with sample output :

code:

#include<iostream>
#include<fstream>

using namespace std;
//student structure
struct student
{
   int id;
   float gpa;
};
//node structure
struct node
{
   student *data;
   node *link;
};
//linklist class
class List
{
   private:
       node *head;
   public:
       List()
       {
           head=NULL;
       }
       //function to insert data into List
       void Insert(student *S)
       {
           node *ptr=head;
           node *temp=new node();
           temp->data=S;
           temp->link=NULL;
           if(ptr==NULL)
           {
               head=temp;
           }
           else
           {
               while(ptr->link!=NULL)
               {
                   ptr=ptr->link;
               }
               ptr->link=temp;
           }
       }
       //function to display data
       void display()
       {
           node *ptr=head;
           if(ptr==NULL)
           {
               cout<<"NO DATA EXISTS"<<endl;
           }
           else
           {
               while(ptr!=NULL)
               {
                   student *s=ptr->data;
                   cout<<s->id<<" "<<s->gpa<<endl;
                   ptr=ptr->link;
               }
           }
       }  
};
int main()
{
   ifstream infile;
   string filename;
   List L;
   int id;
   float gpa;
   cout<<"Enter Filename : ";
   cin>>filename;
   infile.open(filename.c_str());
   if(!infile)
   {
       cout<<"Unable to open file"<<endl;
       return 0;
   }
   while(infile>>id>>gpa)
   {
       student *ptr=new student();
       ptr->id=id;
       ptr->gpa=gpa;
       L.Insert(ptr);
   }
   //displaying data to Console
   cout<<"STUDENT DATA"<<endl;
   L.display();
}


Related Solutions

Write down a C program which will create a list (simple linear linked list) of nodes....
Write down a C program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a grade-point average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function you wrote...
C++ Write a program to create a linked list which stores the details of employees(Employee number,...
C++ Write a program to create a linked list which stores the details of employees(Employee number, employee name, rate, hours worked). Create a menu to manage the emoployee data. MENU 1. ADD EMPLOYEE DETAILS 2. DELETE EMPLOYEE 3. SEARCH EMPLOYEE 4. PRINT EMPLOYEE PAYROLL 5. EXIT When the user selected option #4 the program should print the following pay report for each employee: EmpNo.     Name      Rate    Hours    Regular Pay      Overtime Pay     Gross Pay Any hours worked above 40 hours are...
Bank Linked List Project: Create a bank linked list project program to mimic a simple bank...
Bank Linked List Project: Create a bank linked list project program to mimic a simple bank account system (open account, deposit, withdraw, loans etc.). Requirements: 1. Use linked list (queues and/or stacks) 2. Classes 3. Arrays 4. Add, delete, remove, search methods (use Dev. C++ to create the program)
1.Please write a C++ program that counts the nodes in a linked list with the first...
1.Please write a C++ program that counts the nodes in a linked list with the first node pointed to by first. Also please explain. 2. Write a program to determine the average of a linked list of real numbers with the first node pointed to by first. 3. Determine the computing times of the algorithms in question 1 and 4. Write a program to insert a new node into a linked list with the first node pointed to by first...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
Write a program where you- 1. Create a class to implement "Double Linked List" of integers....
Write a program where you- 1. Create a class to implement "Double Linked List" of integers. (10) 2. Create the list and print the list in forward and reverse directions. (10)
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
Create a C++ integer linked list program that performs the following methods below: Please create these...
Create a C++ integer linked list program that performs the following methods below: Please create these three source files: intList.h, intList.cpp, & intListTest.cpp. Implement recursive routines in the intList class to do the following: Print the list in reverse order Return the value in the middle node Return the average of all the odd values Remove every node containing an odd value Modify main (in IntListTest.cpp) so it does the following: Insert the numbers 1, 3, 4, 6, 7, 10,...
Write a program that create a single linked list and consist of all the necessary functions...
Write a program that create a single linked list and consist of all the necessary functions to do the following Add an element to the list, insertion position can be anywhere in the list (first, last and middle) delete an element from the list, deletion position can be anywhere in the list (first, last and middle) Note: You need to add proper documentation to your programs and you need to include the output of each program C++
Write in C++: create a Doubly Linked List class that holds a struct with an integer...
Write in C++: create a Doubly Linked List class that holds a struct with an integer and a string. It must have append, insert, remove, find, and clear.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT