Question

Write a c/c++ program to read a list of students from a file and create a...

Write a c/c++ program to read a list of students from a file and create a list. The program should
use a linked list for implementation. Each node in the linked list should have the student’s
name, a pointer to the next student, and a pointer to a linked list of scores. There may be
up to four scores for each student.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ PROGRAM

/* I am create text file (studmarks.txt) with following data records

xxxx 54 66 77 88
yyyy 99 56 76 98
zzzz 65 76 55 66
tttt 98 55 49 66
pppp 88 98 56 77 */

#include<iostream>
#include<fstream>
using namespace std;

// implement stucture Node
typedef struct Node
{
   string name; // declare string object 'name'
   int m1,m2,m3,m4; // declare integer variables m1,m2,m3 and m4
   Node *next; // self-reference pointere next
}*headptr; // declare structure pointer headptr

// implement addNode() function
// with 6 parameters
// first parameter structure reference object head
// second parameter string object 'name'
// remaining integer variables for scores m1,m2,m3 and m4
// Return type structure object with reference
headptr &addNode(headptr &head,string name,int m1,int m2,int m3,int m4)
{
   headptr temp=new Node(); // create temp node
   // store values into temp
   temp->name=name;
   temp->m1=m1;
   temp->m2=m2;
   temp->m3=m3;
   temp->m4=m4;
  
   temp->next=NULL; // and assign next pointer is NULL
  
headptr p=head; // create another node p and assing head node
if(p==NULL) // check p node is null then,
   head=temp; // assign temp node to head
else{ // else,
    while(p->next!=NULL) // create while loop p->next != null
       p=p->next; // traversing p node until next
    p->next=temp; // assign temp to p->next
   }
  
   return head; // return head node
}

// implement displayList() function with single parameter i.e., node reference head
void displayList(headptr &head)
{
   headptr temp; // declare temp node
   temp=head; // assign head node to temp
  
   while(temp!=NULL) // create while loop until temp!=null
   {
       // display student records
       cout<<"Student Name: "<<temp->name<<endl;
       cout<<"Score-1 = "<<temp->m1<<endl;
       cout<<"Score-2 = "<<temp->m2<<endl;
       cout<<"Score-3 = "<<temp->m3<<endl;
       cout<<"Score-4 = "<<temp->m4<<endl;
       cout<<endl;
       temp=temp->next; // traversing until temp->next=NULL
   }
}

int main()
{
   string name; // declare string object name
   int m1,m2,m3,m4; // declare integer variable m1,m2,m3 and m4
  
   ifstream in; // create object 'in' from ifstream class
  
   headptr head=NULL; // create head node and set null
   in.open("d:\\studmarks.txt"); // open file in read mode with in object
  
   while(in>>name>>m1>>m2>>m3>>m4) // create whil loop and read all values from file
{
  
addNode(head,name,m1,m2,m3,m4); // calling addNode() function
  
  
       }
   cout<<"Student Details:"<<endl<<endl;  
   displayList(head); // calling displayList() function
  
   return 0;
}

OUTPUT

Student Details:

Student Name: xxxx
Score-1 = 54
Score-2 = 66
Score-3 = 77
Score-4 = 88

Student Name: yyyy
Score-1 = 99
Score-2 = 56
Score-3 = 76
Score-4 = 98

Student Name: zzzz
Score-1 = 65
Score-2 = 76
Score-3 = 55
Score-4 = 66

Student Name: tttt
Score-1 = 98
Score-2 = 55
Score-3 = 49
Score-4 = 66

Student Name: pppp
Score-1 = 88
Score-2 = 98
Score-3 = 56
Score-4 = 77

Add a comment
Know the answer?
Add Answer to:
Write a c/c++ program to read a list of students from a file and create a...
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
  • C++ Data Structure Write a program to read a list of students from a file and...

    C++ Data Structure Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.

  • Help in JAVA please Write a program that reads a list of students (first names only)...

    Help in JAVA please Write a program that reads a list of students (first names only) from a file. It is possible for the names to be in unsorted order in the file but they have to be placed in sorted order within the linked list. The program should use a doubly linked list. Each node in the doubly linked list should have the student’s name, a pointer to the next student, and a pointer to the previous student. Here...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • For C++ program Your program should first prompt the user for the number of students they...

    For C++ program Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have...

  • Write a C++ program to store and update students' academic records in a binary search tree....

    Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:               1) Student name - the key field (string);               2) Credits attempted (integer);               3) Credits earned (integer);               4) Grade point average - GPA (real).                             All student information is to be read from a text file. Each record in the file represents the grade information on...

  • Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written...

    Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...

  • please use the c language Assignment 12 The program to write in this assignment is a...

    please use the c language Assignment 12 The program to write in this assignment is a program that calculates score statistics and manages the grades of the students. First, the student list and are given in a file named "student.dat" as in the following: 이성우 77 홍길동 88 scores 201 1710086 2012700091 This program reads the input file "student.dat" and keeps this data in a linear linked list. Each node must be a struct which contains the following: student id...

  • c++ File name: 2170 107b.ee Purpose: This program demonstrates the use of multi-linked lists. //This file...

    c++ File name: 2170 107b.ee Purpose: This program demonstrates the use of multi-linked lists. //This file contains the implementation file for the 2170_10_7b.h header file. This implementation uses a dynamic linked list structure implementing the // Multi ListClass object. The implementation uses nodes which have two pointer fields one to point to the next record by name (nextName) and one to point Ito the next record by account number(nextNum). The linked list is also maintained I with a dummy header...

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