write a c++ program and use visual studio Write a program that will input a stud
ID: 3717209 • Letter: W
Question
write a c++ program and use visual studio
Write a program that will input a student's name and four test scores. you want to understand what affect there is if you "toss out" the lowest grade. Thank goodness you only have 3 students in your class and only four scores for each student. you do not need to do any error checking for valid input (see below for the exception to this direction). calculate the average with and without the lowest score and display the results in the following format:
1 2 3 4 Low Average (4) Average (3)
Sally 95 75 83 89 75 85.5 89.0
Billy 78 79 88 91 nn xxxx yyyy
Student3 a b c d e xxxx yyyy
You Must use functions to make your code easy to follow. At a minimum, you must have separate function for the following program parts:
1) Find the low number
2) Calculate the average
3) Display the results
You must use arrays as your data structure. You can use a one or two dimensional array. if you want, you can use multiple dimensional arrays.
Sample output:
Note: The italicized data is user inputs.
Input the name of student 1: sally
Input the 4 scores for sally: 95, 75, 83, 89
Input the name of student 2: Billy
Input the 4 scores for Billy: 78, 79, 88, 91
Explanation / Answer
//example.cpp
#include <iostream>
using namespace std;
// function declaration
int min(int S_1, int S_2,int S_3,int S_4);
float avg(int S_1, int S_2,int S_3,int S_4);
void display(string name, int S_1, int S_2,int S_3,int S_4,float l1,float a1);
//main function
int main() {
//varible declarations
string S1,S2,S3;
int S1_1,S1_2,S1_3,S1_4,S2_1,S2_2,S2_3,S2_4,S3_1,S3_2,S3_3,S3_4;
float l1,l2,l3,a1,a2,a3;
//Student 1 detials
cout<<"Input the name of student 1"<<endl;
cin>>S1;
cout<<"Input the 4 scores for "<<S1;
cin>>S1_1;cout<<",";cin>>S1_2;cout<<",";cin>>S1_3;cout<<",";cin>>S1_4;cout<<",";
l1=min(S1_1,S1_2,S1_3,S1_4);
a1=avg(S1_1,S1_2,S1_3,S1_4);
//Student 2 detials
cout<<"Input the name of student 2"<<endl;
cin>>S2;
cout<<"Input the 4 scores for "<<S2;
cin>>S2_1;cout<<",";cin>>S2_2;cout<<",";cin>>S2_3;cout<<",";cin>>S2_4;cout<<",";
l2=min(S2_1,S2_2,S2_3,S2_4); //function call
a2=avg(S2_1,S2_2,S2_3,S2_4); //function call
//Student 3 detials
cout<<"Input the name of student 3"<<endl;
cin>>S3;
cout<<"Input the 4 scores for "<<S3;
cin>>S3_1;cout<<",";cin>>S3_2;cout<<",";cin>>S3_3;cout<<",";cin>>S3_4;cout<<","<<endl;
l3=min(S3_1,S3_2,S3_3,S3_4); //function call
a3=avg(S3_1,S3_2,S3_3,S3_4); //function call
//dispaly part
cout<<"Name"<<" "<<"Subject1"<<" "<<"Subject2"<<" "<<"Subject3"<<" "<<"Subject4"<<" "<<"Low"<<" "<<"Avg"<<endl;
display(S1,S1_1,S1_2,S1_3,S1_4,l1,a1); //function call
display(S2,S2_1,S2_2,S2_3,S2_4,l2,a2); //function call
display(S3,S3_1,S3_2,S3_3,S3_4,l3,a3); //function call
}
//Min value finding function defination
int min(int S_1, int S_2,int S_3,int S_4) {
int min=S_1;
if(S_2<min)
min=S_2;
if(S_3<min)
min=S_3;
if(S_4<min)
min=S_4;
return min;
}
//Average function defination
float avg(int S_1, int S_2,int S_3,int S_4) {
return (float)(S_1+S_2+S_3+S_4)/4;
}
//display function defination
void display(string S,int S_1, int S_2,int S_3,int S_4,float l1,float a1)
{
cout<<S<<" "<<S_1<<" "<<S_2<<" "<<S_3<<" "<<S_4<<" "<<l1<<" "<<a1<<endl;
}
Output :
Name Subject1 Subject2 Subject3 Subject4 Low Avg
abc 10 20 30 40 10 25
xyz 1 2 3 4 1 2.5
nm 3 5 7 9 3 6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.