}
/*
void printInfo ()
post: Information is posted on the Screen.
*/
void printInfo()
{
cout << "Enter three scores for three different exams.";
cout << "The program will calculate ";
cout << "\nthe average and then display the average.";
}
// Askes user to enter a value and gets score
int getScore ()
{
int score;
cout << "Enter a value: ";
cin >> score;
return score;
}
________________________________________________________________________
These are the directions for what I have left to do:
3) Add statement in main(), after the work done in part 2 above, to call the
calcAverage() passing the three scores and then return the average. It will
be something like this:
average = calcAverage(score1,score2,score3);3
4) Add definition for your calcAverage() function by taking in the three values
passed and then calculate and return the value for average.
5) After the statement done in step 3 of this task (above) add a statement to
print the value for average returned from the calcAverage() function.
6) Run your program and enter three different scores and check that the average
is calculated (and displayed) correctly.
Do continue if this process is not working correctly.
7) Add documentation for your function; what it does, preconditions and
postconditions.
Part 4.
1) Then add a prototype (before the main function) for a function called
printOutput() with the following prototype.
void printOutput(int score1,int score2,int score3,double average);
Note that prototype could also be like this
void printOutput(int ,int ,int ,double);
That is, only the data type is mandatory.
2) In your main function, add a statement (after work done for part 3 above)
that will call the printOutput() function. It will be like this.
printOutput(score1,score2,score3,average);
3) Add definition for your printOutput() function by printing the three scores
and also their averages.
4) Run your program and test that the average is displayed correctly. You still
should have the statement in main() that print the average, and this value
and the value displayed in the printOutput() function should agree.
Do continue if this process is not working correctly.
5) Add documentation for your function; what it does, preconditions and
postconditions.
Lastly, remove all the cout statements in the main (and may be in your functions)
that was put in for debugging purposes.
You are right, it does lead you through a step at a time. Let's look at the first part:
1) First implement a prototype (before the main function) for a function called
printInfo() with the following prototype.
void printInfo();
2) Write your main() function and add a statement to call the printInfo()
function. That should be the only statement in main()
It actually supplies the code, verbatim for the first part, so that's done for you: void printInfo();
Then for the next part is says to write function main() and says there is to be only one statement within main().
So the complete program so far looks like this:
1 2 3 4 5 6
void printInfo();
int main()
{
printInfo();
}
That's steps 1 and 2 completed. Some of the later steps may be a bit harder, but I think you should consider the instructions as helping you complete the project, guiding you through it. Hope this helps.
If you are not able to do this assignment, you don't will to pass your course!
study carefully this code! and first chapters of C++ programming!
Best regards!
WRITE WHAT YOUR PROGRAM DOES HERE!
Enter score: 4
Enter score: 19
Enter score: 32
Scores:
Score 1: 4
Score 2: 19
Score 3: 32
------------
Average: 18.3333
//Assignment.cpp
//Add description;
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
void printInfo(); //function prototype
int setScore();
double getAverage(int score1,int score2,int score3);
void printOutput(int,int,int,double); //parameter names are not mandatory
//to the function prototype, but please is meaningful to the programmer.
int main(){
int score1=0;
int score2=0;
int score3=0;
double average;
printInfo(); //function call to printInfo
score1=setScore(); //assign -set- new values
score2=setScore();
score3=setScore();
average=getAverage(score1,score2,score3); //calculate score average
printOutput(score1,score2,score3,average); //function call to printOutput
return 0; //indicates success
}//end main
//function to print what the program does
void printInfo(){
cout<<"\nWRITE WHAT YOUR PROGRAM DOES HERE!\n"<<endl;
}//end function printInfo
//function to initialize scores
int setScore(){
int score;
cout<<"Enter score: ";
cin>>score;
return score;
}//end function setScore
//function to calculate score average
double getAverage(int score1,int score2,int score3){
int total=0;
total=score1+score2+score3;
returnstatic_cast<double>(total)/3; //Attention here to get decimal precision
//from calculate total/3
//you have to convert -temporally- variable total of type int to double,
//and this is what this statement does. static_cast<double>(total)/3;
}//end function getAverage
//function definition for printOutput
void printOutput(int score1,int score2,int score3,double average){
cout<<"\nScores:\n";
cout<<"\nScore 1: "<<score1
<<"\nScore 2: "<<score2
<<"\nScore 3: "<<score3<<endl;
cout<<"------------"
<<"\nAverage: "<<average<<endl;
}//end function printOutput
4) Add definition for your calcAverage() function by taking in the three values
passed and then calculate and return the value for average.
5) After the statement done in step 3 of this task (above) add a statement to
print the value for average returned from the calcAverage() function.
6) Run your program and enter three different scores and check that the average
is calculated (and displayed) correctly.
Do continue if this process is not working correctly.
7) Add documentation for your function; what it does, preconditions and
postconditions.
Part 4.
1) Then add a prototype (before the main function) for a function called
printOutput() with the following prototype.
void printOutput(int score1,int score2,int score3,double average);
Note that prototype could also be like this
void printOutput(int ,int ,int ,double);
That is, only the data type is mandatory.
2) In your main function, add a statement (after work done for part 3 above)
that will call the printOutput() function. It will be like this.
printOutput(score1,score2,score3,average);
3) Add definition for your printOutput() function by printing the three scores
and also their averages.
4) Run your program and test that the average is displayed correctly. You still
should have the statement in main() that print the average, and this value
and the value displayed in the printOutput() function should agree.
Do continue if this process is not working correctly.
5) Add documentation for your function; what it does, preconditions and
postconditions.
average = calcAverage (score1, score2, score3);
printOutput (score1,score2,score3,average);
return 0;
}
/*
void printInfo ()
post: Information is posted on the Screen.
*/
void printInfo()
{
cout << "Enter three scores for three different exams.";
cout << "The program will calculate ";
cout << "\nthe average and then display the average.";
}
// Askes user to enter a value and gets score
int getScore ()
{
int score;
cout << "Enter a value: ";
cin >> score;
return score;
}
Just follow the instructions...these instructions are so simple, just need to know the basic concepts about functions prototypes,definitions, return types and parameter list, what is a calling function, and thats all!