Question

In: Computer Science

C++ program that will ask the user for how many test scores will be entered. Setup...

  1. C++ program that will ask the user for how many test scores will be entered.
  2. Setup a while loop with this loop iteration parameter. The data will include the student’s first name and midterm score
  3. Print out the completed test scores to a file (midTermScores.txt) .
  4. Print out list of students names and grades
  5. in the print out, a letter grade should replace numeric score using standard grading (a = 90 – 100, b=80-90, c=70-80, d=60-70, f=below 60)

Solutions

Expert Solution

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

int main(){
        
        int nscores;
        
        cout << "Number of Test scores : ";
        cin >> nscores;
        
        string fnames[nscores];
        float scores[nscores];
        
        int i=0;
        
        // Reading first names and test scores
        while( i < nscores ) {
                cout << "Enter First Name : ";
                cin >> fnames[i];
                cout << "Enter Score : ";
                cin >> scores[i];
                i++;
        }
        
        i = 0;
        
        // printing names and test scores
        cout << "--------------------------------"<<endl;
        
        cout << "Name"<<"\t"<<"Score" << endl;
        
        while( i < nscores ) {
                cout << fnames[i] <<"\t"<< scores[i] <<endl;
                i++;
        }
        
        cout << "--------------------------------"<<endl;
        
        
        int j = 0;
        
        ofstream fs;
        
        //clearing file with empty text
        fs.open("midTermScores.txt");
        fs << "";
        fs.close();
        
        fs.open("midTermScores.txt", ios::app);
        
        // writing first name and scores on file
        while( j < nscores ) {
                fs << fnames[j] <<"\t"<< scores[j] <<endl;
                j++;
        }
        
        // closing file
        fs.close();
        
        
        int k = 0;
        
        // printing firstnames and grades
        cout << "Name"<<"\t"<<"Grade" << endl;
        while( k < nscores ) {
                
                int n = scores[k];
                char grade;
                if( n >= 90 && n <= 100 ){
                        grade = 'A';
                }else if(n >= 80 && n < 90){
                        grade = 'B';
                }else if(n >= 70 && n < 80){
                        grade = 'C';
                }else if(n >= 60 && n < 70){
                        grade = 'D';
                }else{
                        grade = 'F';
                }
                cout << fnames[k] << "\t" << grade <<endl;
                k++;
        }
        
        return 1;
}

Output:


Related Solutions

Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate the average score and scores below 60. Then display the average score and number of scores below 60
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
The JAVA program should do the following: –Ask the user for how many lines of text...
The JAVA program should do the following: –Ask the user for how many lines of text they wish to enter –Declare and initialize an array of Strings to hold the user’s input –Use a while loop to prompt for and read the Strings (lines of text) from the user at the command line. Typically, this would be a 'for' loop since we know the number of times to execute the loop based upon the number supplied by the user, but...
C Programming use notes Start by asking the user how many grades are to be entered....
C Programming use notes Start by asking the user how many grades are to be entered. Then ask for each one of theses grades. Calculate the average grade and the number of failing grades (grade less than 70). Display on the screen the average grade and the number of failing grades
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Implement a program in C++ that does the following: Ask the user and read at least...
Implement a program in C++ that does the following: Ask the user and read at least 10 numbers as input from the keyboard and stores them in a an array Displays the array of numbers on the screen (as is, before sorting) Sorts those numbers in the array using Selection Sort Algorithm Displays the array of numbers on the screen (AFTER sorting)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT