Function Format

I really need help with this, i have way to much to do and i am just lost on how to write this program if anyone can help.

Function Format
Purpose
To create and execute a C++ program with functions to read student name and scores
input from a keyboard, calculate the test average, program average, course average, and
the letter grade earned and output the result to the monitor as well as to an output text
file. Program must allow grades to be calculated for one or more number of students.
The letter grade earned must be based on the course average (the average of the program
and test scores) as shown below.

Course Average Letter Grade
>=90% A
80% - 89% B
70% - 79% C
Below 70% F

You are required to use a function to accomplish each of the following:
1. Output descriptive header (void function with no parameters)
2. Prompt user for name and program/test scores and read the input (void function with
reference parameters)
3. Check to ensure each input score is not less than 0 or greater than 100. Prompt user to
reenter score if not within specified range (value returning function with parameter)
4. Calculate averages (void function with value and reference parameters)
5. Assign letter grade (value returning function with parameter)
6. Output student name, total points, and program, test, and course averages to monitor
and text file. (void function with value parameters)




this is what i have so far

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

//Global variables/constants, function prototypes
void headerfn();//void function with no parameters
void inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3);
float inputfn(string input);
char gradefn(float avg);
void outputfn(float avg, char grade);

int main(){
system("color f0");
headerfn();//void function call

int prog1, prog2, prog3, test1, test2, test3;
inputfn(prog1, prog2, prog3, test1, test2, test3);

string fname, lname;
namefn(fname,lname);//fn call
cout<<"Your first and last name is "<<fname+' '+lname<<endl;// the results

float input;
input=inputfn(fname, lname, prog1, prog2, prog3, test1, test2, test3);

float average;
char grade;

average=coursefn();
cout<<"Avg= "<<average<<endl;

grade = gradefn(average);

cout<<"Grade = "<<grade<<endl;

outputfn(average, grade);

system("pause");
return 0;
}//end of main

//************************************************************
//Void Function Without Parameters
void headerfn(){
cout<<"123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<setw(60)<<setfill('*')<<"*"<<endl;
cout<<"* *";
cout<<"* information from the keyboard and outputs *";
cout<<"* the results to the monitor and a text file. *";
cout<<setw(60)<<setfill('*')<<"*"<<endl;
}//end of headerfn




//************************************************************
//Void Function With Parameters
void inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){

void namefn(string &fname, string &lname){
cout<<" Enter your first and last name: ";
cin>> fname>>lname;
}




cout<<"Please enter the first program score: ";
cin>>prog1;
cout<<"Please enter the second program score: ";
cin>>prog2;
cout<<"Please enter the third program score: ";
cin>>prog3;
cout<<"Please enter the first test score: ";
cin>>test1;
cout<<"Please enter the second test score: ";
cin>>test2;
cout<<"Please enter the third test score: ";
cin>>test3;
cout<<fixed<<showpoint<<setprecision(2);
average=(test1+test2+test3)/3;
cout<<"Average: "<<average<<endl;

void outputfn(float avg, char grade){
cout<<"Average = "<<avg<<endl;
<<"Grade = "<<grade<<endl;

string grade;
if(average>=90){grade="A";}
else if(average>=80){
if(test1>95||test2>=95||test3>=95){grade="A";}
else{grade="B";}
}
else if(average>=70){
if(test1>=85||test2>85){grade="B";}
else{grade="C";}
}
else{grade="F";}




//************************************************************
//Value Returning Function With Parameter
float inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3,int &test1, int &test2, int &test3){
float input;
if (input<0) cout<<"This score is invalid! PLease enter a score between 0-100: ";
else if (input>100) cout<<"This score is invalid! PLease enter a score between 0-100: ";

cout<<"123456789123456789123456789123456789123456789012345678901234\n";
cout<<"============================================================\n";
cout<<endl;


cout<<left<<setw(25)<<"FIRST NAME"
<<setw(25)<<"LAST NAME"<<endl;
cout<<left<<setw(15)<<firstName
<<setw(15)<<lastName<<endl;
cout<<setw(25)<<setfill('-')<<"-"<<setfill(' ')<<endl;

cout<<setw(25)<<setfill('-')<<"-"<<setfill(' ')<<endl;


cout<<left<<setw(15)<<setfill('-')<<"Program Average"
<<right<<setw(10)<<setfill('-')<<programAverage<<endl<<endl;

cout<<left<<setw(15)<<setfill('-')<<"Test Average"
<<right<<setw(10)<<setfill('-')<<testAverage<<endl<<endl;

cout<<left<<setw(15)<<setfill('-')<<"Course Average"
<<right<<setw(10)<<setfill('-')<<courseAverage<<endl<<endl;

cout<<left<<setw(15)<<setfill('-')<<"Letter Grade"
<<right<<setw(10)<<setfill('-')<<letterGrade<<endl<<endl;


cout<<"____________________________________________________________\n";


cout<<"Please enter 1 for another student or 0 to exit: ";
cin>>flag;
}while(flag);



return input;
}
Last edited on
Why did you take a programming class if your not interested in learning to program ?

Below is the layout for your program. Now your not lost. Good luck!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <fstream>
#include <iostream>
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 

using namespace std;

void Header()
{
cout << "1. Output descriptive header (void function with no parameters)" << endl;
}

void UserInput()
{
cout << "2. Prompt user for name and program/test scores and read the input (void function with reference parameters)" << endl;
}

void CheckValues()
{
cout << "3. Check to ensure each input score is not less than 0 or greater than 100. Prompt user to" << endl;
cout << "reenter score if not within specified range (value returning function with parameter)" << endl;
}

void CalculateAverages()
{
cout << "4. Calculate averages (void function with value and reference parameters)" << endl;
}

void AssignGrade()
{
cout << "5. Assign letter grade (value returning function with parameter)" << endl;
}

void OutPut()
{
cout << "6. Output student name, total points, and program, test, and course averages to monitor " << endl;
cout << "and text file. (void function with value parameters)" << endl;
}

int main()
{

Header();
UserInput();
CheckValues();
CalculateAverages();
AssignGrade();
OutPut();

    return 0;
}



You should take some time to read this or your book on functions.
http://www.cplusplus.com/doc/tutorial/functions/

Topic archived. No new replies allowed.