Question

C++ Homework Help:

Working with Data The given input file has records that look like this: Name: Peter Parker CSCI-261: 95 CSCI-262: 90.625 CSCICSCI-442: Operating Systems CSCI-562: Applied Algorithms & Data Structures CSCI-565: Distributed Computing Systems CSCI-580:Putting it all together Download the provided text file that contains example input records. (Place this file at the project

The text file that it wants you to download is this:

Name: Peter Parker
CSCI-261: 95
CSCI-262: 90.625
CSCI-442: 91.20

Name: Mary Smith
CSCI-442: 65.0
CSCI-562: 79.1234
CSCI-580: 70.24

Name: Pat Brown
CSCI-562: 95
CSCI-565: 88.0
CSCI-580: 91.20

Name: Linda Williams
CSCI-262: 65.0
CSCI-306: 67.719
CSCI-562: 70.200

Name: John Miller
CSCI-261: 95.281
CSCI-306: 90.625
CSCI-565: 91.20

Name: Patricia Johnson
CSCI-306: 65.012
CSCI-442: 84.76
CSCI-580: 70

Name: Brian Hall
CSCI-261: 65.0
CSCI-306: 84.712
CSCI-442: 75.24

Name: Sandra Nelson
CSCI-262: 95.281
CSCI-306: 90.625
CSCI-565: 91.20

Name: Jason Baker
CSCI-261: 65.012
CSCI-306: 84.76
CSCI-442: 70

Name: Gary Carter
CSCI-562: 65.0
CSCI-565: 84.712
CSCI-580: 75.24

Working with Data The given input file has records that look like this: Name: Peter Parker CSCI-261: 95 CSCI-262: 90.625 CSCI-442: 91.20 Name Mary Smith CSCI-442: 65.0 CSCI-562: 79.1234 CSCI-580: 70.24 Our goal is to loop through the file, and 1. Determine the average grade of each student. 2. Count the number of students taking undergraduate and graduate level courses. 3. Count the number of students taking each course. Undergraduate and graduate level courses Courses 500 and above are graduate level courses. The rest are undergraduate level courses. Identifying various courses - The following lists the courses offered by the CS program at Mines, as well as their abbreviations (which you need for Step 3) CSCI-261: Programming Concepts CSCI-262: Data Structures CSCI-306: Software Engineering CSCI-442: Operating Systems CSCI-562: Applied Algorithms & Data Structures
CSCI-442: Operating Systems CSCI-562: Applied Algorithms & Data Structures CSCI-565: Distributed Computing Systems CSCI-580: Advanced High Performance Computing Using the provided input file, your output file should include: Name: Parker, Peter Average Score: 92.27 Name: Smith, Mary Average Score: 71.45 There are 18 instances of students taking undergraduate level courses. There are 12 instances of students taking graduate level courses. CSCI-261: Programming Concepts has 4 students. CSCI-442: Operating Systems has 5 students. Putting it all together Download the provided text file that contains example input records. (Place this file at the project level, which is the same directory as your main.cpp file. Then follow these steps. 1. Start a new project from scratch 2. Declare an ifstream Object associated with the input file; Verify that you opened the file. 3. Also declare an ofstream object associated with an output file called output.txt. 4. Loop through the input file with an EOF while loop. 5. Read each record in the file. 6. Format the name to match the output format
Putting it all together Download the provided text file that contains example input records. (Place this file at the project level, which is the same directory as your main.cpp file. Then follow these steps. 1. Start a new project from scratch 2. Declare an ifstream object associated with the input file; Verify that you opened the file. 3. Also declare an ofstream object associated with an output file called output.txt. 4. Loop through the input file with an EOF while loop. 5. Read each record in the file. 6. Format the name to match the output format 7. For each of the courses, use the first part (e.g., CSCI-442) to identify the course. You then need to count the number of students in each course; since there are seven courses in total, perhaps create an array with seven elements. Hint: Write a function that takes a string as an input and returns an integer as an output. For example, if the input to the function is CSCI-261 then the output is 0. If the input is CSCI-562, then the output is 4. You can use the different course numbers in a switch statement to return the position within the array when ordered numerically. For example, perhaps have: int getCourseNumberIndex(string course); 8. Read the scores into a vector of type double and use the scores to find the average. 9. Format the data from the input file as required for the output file. 10. Write the formatted output to the output file. You can update the output file after each student's details are read and his/her average calculated. Note that the average in the output file contains exactly two decimal places. 11. You need to calculate the number of students per course, as well as the number of students in graduate and undergraduate level courses during your loop; however, you need to write these details to your output file after the loop has ended 12. Close both input and output files.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include <numeric>
#include<iomanip>

using namespace std;
int getCourseNumberIndex(string course);
int main()
{
   ifstream inFile;
   ofstream outFile;

   inFile.open("grades.txt");
   outFile.open("output.txt");

   if(!inFile)
   {
       cout<<"Unable to open the file! Exiting......"<<endl;
       return 1;
   }
   string firstName,lastName,subject,name,subName;
   int underGraduateCount=0,graduateCount=0;
   double mark;
   vector<double>score;
   int subCount[]={0,0,0,0,0,0,0},index;
   string courses[]={"CSCI 261: Programing Concepts","CSCI-262: Data Structure","CSCI-262: Software Engineering","CSCI-262: Operating System","CSCI-262: Applied ALgoritham & Data Structures","CSCI-262: Distributed Computing System","CSCI-262: Advanced High Performance Computing"};
   outFile << fixed << setprecision(2) ;
   while(inFile>>name>>firstName>>lastName)
   {
       inFile>>subName>>mark;
       index=getCourseNumberIndex(subName);
       subCount[index]+=1;
       if(index<4)
           underGraduateCount++;
       else
           graduateCount++;
       score.push_back(mark);
       inFile>>subName>>mark;
       index=getCourseNumberIndex(subName);
       if(index<4)
           underGraduateCount++;
       else
           graduateCount++;
       subCount[index]+=1;
       score.push_back(mark);
       inFile>>subName>>mark;
       index=getCourseNumberIndex(subName);
       subCount[index]+=1;
       if(index<4)
           underGraduateCount++;
       else
           graduateCount++;
       score.push_back(mark);

       double average = accumulate( score.begin(), score.end(), 0.0)/score.size();
      
       score.clear();
       outFile<<"Name: "<<lastName<<", "<<firstName<<endl;
       outFile<<"Average Score: "<<average<<endl<<endl;
   }
   inFile.close();
   outFile<<"There are "<<underGraduateCount<<" instance of students taking undergraduate level courses."<<endl;
   outFile<<"There are "<<underGraduateCount<<" instance of students taking graduate level courses."<<endl<<endl;
   for(int i=0;i<7;i++)
   {
       outFile<<courses[i]<<" has "<<subCount[i]<<" students."<<endl;
   }
   outFile.close();
   return 1;
}
int getCourseNumberIndex(string course)
{
   if(course=="CSCI-261:")
       return 0;
   else if(course=="CSCI-262:")
       return 1;
   else if(course=="CSCI-306:")
       return 2;
   else if(course=="CSCI-442:")
       return 3;
   else if(course=="CSCI-562:")
       return 4;
   else if(course=="CSCI-565:")
       return 5;
   else if(course=="CSCI-580:")
       return 6;

}

output

output.txt

output Notepad File Edit Format View Help Name: Parker, Peter Average Score: 92.27 Name: Smith, Mary Average Score: 71.45 Namoutput Notepad File Edit Format View Help Name: Brown, Pat Average Score: 91.48 Name: Williams, Linda Average Score: 67.64 NaIf 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++ Homework Help: The text file that it wants you to download is this: Name: Peter...
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
  • 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...

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

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

  • Hello I need help fixing my C++ code. I need to display in the console the...

    Hello I need help fixing my C++ code. I need to display in the console the information saved in the file as well have the content saved in the file output in a fixed position like the screenshot. Thanks. CODE #include<iostream> #include<fstream> #include<iomanip> using namespace std; //main function int main() {    //variable to store student id    int id;       //variables to store old gpa(ogpa), old course credits(occ), new course credits(ncc), current gpa(cur_gpa), cumulative gpa(cum_gpa)    float ogpa,...

  • Declare and initialize 4 Constants for the course category weights: The weight of Homework will be...

    Declare and initialize 4 Constants for the course category weights: The weight of Homework will be 15% The weight of Tests will be 35% The weight of the Mid term will be 20% The weight of the Fin al will be 30% Remember to name your Constants according to Java standards. Declare a variable to store the input for the number of homework scores and use a Scanner method to read the value from the Console. Declare two variables: one...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data...

    need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data file – It has: player ID, player first name, middle initial, last name soccer.txt – Player information file – It has: player ID, goals scored, number of penalties, jersey number output file - formatted according to the example provided later in this assignment a) Define a struct to hold the information for a person storing first name, middle initial, and   last name). b) Define...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

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