Question

C++ A professor plans to store the following data for each of his students: Last Name,...

C++ A professor plans to store the following data for each of his students:

Last Name, First Name, Class Average (as a double), Letter Grade (“A”, “A-“, “B+”, “B”, etc.)

Write two programs for writing and reading such a file, with the user choosing the file name. Store the (int) number of students as the first data value in the file, followed by \n. Then use the following delimiter scheme:

Last Name(comma)First Name(comma)Average(space)Letter Grade(newline)

For the file writer program, input the data for the students from the user with a for-loop. You may write the values directly into the file without storing them in arrays first. For the file reader program, read the data and output it to the console window in a reasonable table format. Use getline for both first name and last name, in case there are white space characters (such as “Cyrus, Billy Ray”). You can use >> for the letter grade if you like. Note: You will probably need to use .ignore() in a few places, since >> will be followed by getline.

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

Code Writer code

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

int main()
{
   ofstream outFile;
   int numberOfrecord;
   string fName,lName;
   double grade;
   string latterGrade;
  
   outFile.open("studentData.txt");

   cout<<"How many records do you want to enter: ";
   cin>>numberOfrecord;

   for(int i=0;i<numberOfrecord;i++)
   {
       cin.ignore();
       cout<<"\nEnter first name of the student: ";
       getline(cin,fName);
      
       cout<<"Enter last name of the student: ";
       getline(cin,lName);
      
       cout<<"Enter student's grade: ";
       cin>>grade;
       cout<<"Enter student's latter grade: ";
       cin>>latterGrade;
       outFile<<fName<<","<<lName<<","<<grade<<","<<latterGrade<<endl;
   }
   cout<<"\n\nRecords are written to the studentData.txt file."<<endl;
   return 1;
}

output

reader code

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

int main()
{
   ifstream inFile;
   string fileName,fName,lName,latterGrade,line;
   double grade;
   cout<<"Enter the file name: ";
   cin>>fileName;

   inFile.open(fileName);

   if(!inFile)
   {
       cout<<fileName<<" not found exiting...."<<endl;
       return 1;
   }
   cout<<endl;
   while(getline(inFile,line))
   {
       std::stringstream linestream(line);
       std::string value;
       getline(linestream,value,',');
       fName=value;
       getline(linestream,value,',');
       lName=value;
       getline(linestream,value,',');
       grade=stod(value);
       getline(linestream,value,',');
       latterGrade=value;
       cout<<fName<<"\t"<<lName<<"\t"<<grade<<"\t"<<latterGrade<<endl;
   }

}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
C++ A professor plans to store the following data for each of his students: Last Name,...
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++ Do not use "cin" to get the names from the user. Use "getline()". Name Arranger...

    C++ Do not use "cin" to get the names from the user. Use "getline()". Name Arranger Write a program that asks for the user’s first, middle, and last names. The names should be stored in three different character arrays. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example,...

  • 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...

  • In C Write a function that asks for the user's first, middle, and last names. The...

    In C Write a function that asks for the user's first, middle, and last names. The names will be entered by the user on a single line and will be stored in three different C-strings. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered...

  • 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...

  • Write a program that processes a data file of names in which each name is on...

    Write a program that processes a data file of names in which each name is on a separate line of at most 80 characters. Here are two sample names: Hartman-Montgomery, Jane R. Doe, J. D. Strings On each line the surname is followed by a comma and a space. Next comes the first name or initial, then a space and the middle initial. Your program should scan the names into three arrays— surname , first , and middle_init . If...

  • C++ Student Test Scores

    Write a program in C++ that reads students' names followed by their test scores. The program should output each student's name folloewd by the test scores and therelevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Suppose that the class has 20students. Use an array of 20 components of type studentType.Your program must output each student's name in this form:last name followed by a comma, followed...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Create a program (Lab9_Act1_Write.py) that will read in data from the keyboard and store it in...

    Create a program (Lab9_Act1_Write.py) that will read in data from the keyboard and store it in a file. Your program should prompt the user for the name of the file to use and then request values be entered until the user is done. This data should be written to two files: a text file, user_file_name.txt and a comma separated value file, user_file_name.csv. To help you with decision making, we suggest that you ask the user to input data representing students’...

  • C++ developing involves ut from a file a person's first name, last name, phone number and...

    C++ developing involves ut from a file a person's first name, last name, phone number and birth a menu driven database application. You need to 4) This program accept as input ogram will be menu driven with the following options: 1) Find a person's information 2) Add a person to the database 3) Edit a person's information 4) Display all records to the screen 5) Quit Option 1 allows the user to enter a name after which you will search...

  • Using C Programming, Write a program that prompts for the user's first and last names. Declare a third array that will hold the user's last name and first name, separated by a comma and space....

    Using C Programming, Write a program that prompts for the user's first and last names. Declare a third array that will hold the user's last name and first name, separated by a comma and space. Use loops to inter through the names one character at a time, storing them into the full name array. Don't forget about the terminating character. Sample run: Enter your first name: john Enter your last name: matthews First name: John Last name: Matthews Full name:...

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