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

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...
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.
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. In paragraph 1 Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. In pragraph 2 Replace "We" with v"i" This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would...
Could you write a c- program that reads a text file into a linked list of...
Could you write a c- program that reads a text file into a linked list of characters and then manipulate the linked list by making the following replacements 1. Replace all “c” with “s” if followed by the characters “e”, “i” or “y”; otherwise 2. Replace "sh" with ph This is the text to be manipulated: Paragraph1 She told us to take the trash out. Why did she do that? I wish she would not do that Paragraph 2 We...
Write a C program that creates and prints out a linked list of strings. • Define...
Write a C program that creates and prints out a linked list of strings. • Define your link structure so that every node can store a string of up to 255 characters. • Implement the function insert_dictionary_order that receives a word (of type char*) and inserts is into the right position. • Implement the print_list function that prints the list. • In the main function, prompt the user to enter strings (strings are separated by white-spaces, such as space character,...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out. YES, an integer can be put into and retrieved from a character array. It's all binary under the hood. In some languages this is very easy (C/C++)...
Write down the C++ Program
 Write a function, which accept three integer values as arguments find the largest of three and then return the largest value to main program. Write a main program which will call the function by passing three integer values and print the value returned by the function.?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT