Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dont copy and paste from another answer. Write a program to read in a collection

ID: 3537429 • Letter: D

Question

Dont copy and paste from another answer.

Write a program to read in a collection of exam scores ranging in value from 0 to 100. Your program should display the category of each score. It should also count and display the number of outstanding scores (90 to 100), the number of satisfactory scores (60 to 89), and the number of unsatisfactory scores (0 to 59). Your program should display the average score at the end of the run. Your program should ensure that each score is valid (in the range 0 to 100).

Program Outputs:

Program Test Plan:

Program Test Results:

Functions

(Repeat this section for each of your functions). Provide the function prototype here.

Function Analysis:

Function Preconditions and Post Conditions:

Function Inputs and Outputs:

Function formulas:

Function Algorithm:

Explanation / Answer

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

using namespace std;


int valid(int n)

{

if(n<0 || n>100)

return 0;


return 1;

}


void displayCategory(int nums)

{

if(nums>=90) { cout<<nums<<" : category-Outstanding score"<<endl; }

else if(nums<90 && nums>=60)

{ cout<<nums<<" : category-Satisfactory score"<<endl; }

else

{ cout<<nums<<" : category-Unsatisfactory score"<<endl; }

  

}



int main () {

  

string name;

int nums,totalscore,n;

//score categories

int out,sat,un;

out=sat=un=0;

n=0;

totalscore=0;

//read exam scores

ifstream myfile ("input.txt");

  

if (myfile.is_open())

{

while ( myfile.good() )

{

myfile >> nums;

if( valid(nums) == 1)

{

totalscore+=nums;

n++;

displayCategory(nums);

//increase count

if(nums>=90) { out++; }

else if(nums<90 && nums>=60)

{ sat++; }

else

{ un++; }

}

}

myfile.close();

}

//display output

cout<<endl;

cout<<"Number of Outstanding scores: "<<out<<endl;

cout<<"Number of Satisfactory scores: "<<sat<<endl;

cout<<"Number of Unsatisfactory scores: "<<un<<endl;

cout<<endl;

  

double avg=totalscore/n;

cout<<"Average Score: "<< avg <<endl;


return 0;

}


/*

Program Analysis:

Program Inputs:

A text file called input.txt, with one score per line.

Program Outputs:

Display category of valid scores.

Display count of each category.

Display average of valid scores.

Program Algorithm:

1. Read Input, one line at a time.

2. Check if inputted number is valid.

3. if number is valid, add to total score, and total nums. Also display its category, and add to its count.

4. repeat till no more input.

5. Display the counts for each category.

6. calculate average score, by dividing total score by total number of valid scores.

7. Display the average score.

Program Test Plan:

Write a sample input.txt in notepad with the following data, and save in program directory.

5

34

235

69

98

56

78

Program Test Results:

5 : category-Unsatisfactory score

34 : category-Unsatisfactory score

69 : category-Satisfactory score

98 : category-Outstanding score

56 : category-Unsatisfactory score

78 : category-Satisfactory score


Number of Outstanding scores: 1

Number of Satisfactory scores: 2

Number of Unsatisfactory scores: 3


Average Score: 56


-----------------------------

Functions

1. int valid(int n)

Function Analysis:

Returns 1 if number is valid, else 0.

Function Preconditions and Post Conditions:

pre-condition: n is a numeric value

post-condition: none

Function Inputs and Outputs:

Input: One integer n.

Output: 1 or 0

Function formulas:

n<0 OR n>100

Function Algorithm:

1.Check if n<0 or n>100

2. return 0 if step 1 is true.

3. else return 1.


-----------------------

2. void displayCategory(int nums)

Function Analysis:

Displays the category of nums score.

Function Preconditions and Post Conditions:

pre-condition: nums is a numeric value

post-condition: display on standard output.

Function Inputs and Outputs:

Input: One integer nums.

Output: Display nums, and its category.

Function formulas:

n>=90

n<90 AND n>=60

Function Algorithm:

1.Check if n>=90, then display category outstanding

2. else Check if n<90 AND n>=60, then display category satisfactory

3. else display category unsatisfactory


;>

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote