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...
Q1) Please create a C++ program that will ask the user for how many test scores...
Q1) Please 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. The data will include the student’s first name, Wayne State Access ID, midterm score and their favorite team (i.e. – Doug, hg1702, 92, Wolverines * - John, hv2201, 99, Warriors). Print out the completed test scores to a file (midTermScores.txt) . Adjust the output as follows: (15 points) a. Scores with the...
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 using C++ that ask the user for the flowing: How many shares to...
Write a program using C++ that ask the user for the flowing: How many shares to be bought: The price per share: Percent commission for the broker for each transaction: Average annual return as of percentage: The program should calculate and display the following: The amount paid for the stock alone (without the commission) The amount of the commissionThe total amount of paid (the payment for stock plus the commission) After TEN years, your shares will worth:
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...
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT