Question

create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for...

create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name i.e. jSmith). Next it will need to read three integer values that will represent the 3 e xam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student.

Below is an example of what the calculation would be for the program.

score1 * .3 + score2 * .3 + score3 * .4

The program will then determine the letter grade for that student and write the user ID and the letter grade to a file "studentGrade.txt"

The standard grading scale will be used:

A --> 90 – 100
B --> 80 - 89.99
C --> 70 - 79.99
D --> 60 - 69.99
F --> below 60

Homework Answers

Answer #1

PLEASE NOTE : FEEL FREE TO ASK ANY DOUBTS by COMMENTING

  • If you want me to add/change anythin, Please let me know by commenting.
  • I used comments for better understanding. Comments starts with ' // '
  • Please refer to the screenshot of the code to understand the indentation of the code

Language : C++ Programming

IDE : Dev C++

Input File : studentInfo.txt

NName1 57 69 59
NName2 80 71 61
NName3 57 61 85
NName4 77 63 58
NName5 77 65 84
NName6 64 55 88
NName7 95 89 95
NName8 92 60 93
NName9 91 87 97
NName10 53 87 89

:::::::::::::::::::::::::::::::::::::::::::: CODE ::::::::::::::::::::::::::::::::::::::::

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

int main(){

   string userID;
   int score1,score2,score3;

   // open file to read
   ifstream reader;
   reader.open("studentInfo.txt");
   // open file to write
   ofstream writer;
   writer.open("studentGrade.txt");

   // check file is opened or not
   if(!reader || !writer){
       cout << "Unable to open/create file.";
       // exit program if file not opened
       return -1;
   }

   // loop until end of file
   while(reader >> userID){
       // read scores
       reader >> score1 >> score2 >> score3;

       // calculate weighted course average
       float wca = score1*0.3+score2*0.3+score3*0.4;

       // calculate grade
       char grade;
       if(wca>=90){
           grade = 'A';
       }
       else if(wca>=80 && wca<90){
           grade = 'B';
       }
       else if(wca>=70 && wca<80){
           grade = 'C';
       }
       else if(wca>=60 && wca<70){
           grade = 'D';
       }
       else{
           grade = 'F';
       }

       // write userID and grad to file
       writer << userID << " " << grade << endl;
   }

   // close file reader and writer
   reader.close();
   writer.close();

   return 0;
}

:::::::::::::::::::::::::::::::::::::::::::: OUTPUT ::::::::::::::::::::::::::::::::::::::::

studentGrade.txt

:::::::::::::::::::::::::::::::::::::: CODE in EDITOR ::::::::::::::::::::::::::::::::::

_________________________________________________________________

Dear Friend, Feel Free to Ask Any Doubts by Commenting. ASAP i'll respond when i'm available.

I'm on a critical Situation. Please Do Not Forget To Give A Thumbs UP +1. It will Helps me A Lot.

Thank YOU :-)

Know the answer?
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
Similar Questions
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare...
Write a C++ program. 1) Write a program that writes the grades for 3 students. Declare a variable of type ofstream which is used to output a stream into a file: ofstream output; // output is the name of the variable Prompt the user to input values for the grades of 3 students. Use the output operator (<<) to write the grades into grades.txt: output << grade1 << " " << grade2 << " " << grade3 << endl; You...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
C Programming: Create a struct named “Student” along with 3 properties, Name, ID, Score Choosing the...
C Programming: Create a struct named “Student” along with 3 properties, Name, ID, Score Choosing the correct data type for each property. Once the program is running, it will check if the student.bin file is exist and if it is not exist, the program will ask user to enter three student information and save them to file student.bin . If the file is exist, read the second student information and print it in console.
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
Write a Java Program, that opens the file "students.txt" The program must read the file line...
Write a Java Program, that opens the file "students.txt" The program must read the file line by line The program parses each line that it reads For example, for this line: 1:mohamed:ali:0504123456:cs102:cs202 The program must print    >ID = 1    >First Name = Mohamed   >Last Name = Ali   >Mobie = 0504123456   >Courses = cs102, cs202 In addition, it adds the mobile phone number into an ArrayList called studentPhoneList Print the content and the size of studentPhoneList Show your results and provide...
Write C++ program to create a student record include a student ID, first name, nickname, course,...
Write C++ program to create a student record include a student ID, first name, nickname, course, subject, and subject marks. Task: Create a function to insert a number of students in the record. Create a function to print all student information by a table. Create a function to print all student information that they're in a specific course chosen by user input. Create a function to search for a student by student ID and print student information. Create a function...
This is a program and my solution. How many times should I test, if I need...
This is a program and my solution. How many times should I test, if I need full coverage of all possible program flows?  Why? Write a program that prompts the user for a grade (0-100) and, whether the student is a graduate student (Y/N). If the student is a graduate student, their grade is reduced by 10%, because we have a higher expectation for a graduate students in an undergraduate class. The program then computes and prints the letter grade is...
You are to write a C program that will read from a file, one or more...
You are to write a C program that will read from a file, one or more sets of x,y coordinates. Each set of coordinates is part of a Cartesian system. A Cartesian coordinate system is a system that specifies each point uniquely in a plane by a pair of numerical coordinates. Your program will determine which quadrant each set belong. - Quadrants are often numbered 1st - 4th and denoted by Roman numerals: I(+,+), II (−,+), III (−,−), and IV...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT