Weighted Average Using notes given in class, create a program which reads simula
ID: 645162 • Letter: W
Question
Weighted Average
Using notes given in class, create a program which reads simulates how I calculate grades for students in programming I. I use a weighted average with homework being worth 40% and each exam being worth 20% each. The program can have multiple input files (homework input file, exam input file) to determine averages. It should also read in a student's first name and last name. All from files. The program should then determine the student's current course grade based on the average.
In addition, your program should also generate an error message when the input file is not found by the program. The program should stop executing if the input file cannot be found. I did not tell you this code in class. I want to you find out how it works on your own. You can find this information in your textbook and also online.
Next, I want you to write in comments what the difference is between using a++ and ++a. Which should we use in our programs? Why? Again, write your answer in a block of comments within your program you submit.
You have to complete the code below:-
#include
#include
#include // this is on the exam
using namespace std;
int main()
{
/*
Let's write a program that will simulate our grading system for this
class. I use a weighted average to determine your course grades.
I do not use total points.
Homework assigned 40% of your total grade
Each exam is worth 20% of your total grade
I determine your overall course average by getting your homework
average and then your exam average and then divide by the total
percent possible
if you have a homework average of 100%
homework 100 * .40 = 40
For each exam
Exam 1 100 * .20 = 20
Exam 2 100 * .20 = 20
(40 + 20 + 20) / 80
*/
// I used multiple input files for this program.
// I have 1 for exams, 1 for homework and 1 for name
// declare an input variable??
// one for homework, one exams, and one student name?
ifstream homework, exams, name;
homework.open("hwgrades.txt");
exams.open("exgrades.txt");
name.open("student.txt");
float hwGrade, hwAvg=0;
float exGrade, exAvg=0;
string fName, lName;
float avg;
int hwCounter=0, exCounter=0;
while(!homework.eof())
{
homework >> hwGrade;
hwAvg = hwAvg + hwGrade;
hwCounter++; // this will be used to determine the
// homework average value later
}
hwAvg = hwAvg / hwCounter;
while(!exams.eof())
{
exams >> exGrade;
exAvg = exAvg + exGrade;
exCounter++; // this will be used to determine the
// homework average value later
}
exAvg = exAvg / exCounter;
name >> fName; // no loop needed for names
name >> lName;
cout << fixed << showpoint << setprecision(2);
// you need to add a few more lines of code to determine
// the weighted average for homework and exams
// Then you need to determine the overall average.
// your program should be flexible for exams. You can
// have up to 3 for this class
wHWAvg = hwAvg * .40;
// each exam is worth 20% of your grade
// add one line of code to determine your exam weighted average
// add one line of code to determine your overall course average
cout << "Student Name: " << lName << ", " << fName << endl;
cout << "Homework Average: " << hwAvg << "%" << endl;
cout << "Exam Average: " << exAvg << "%" << endl;
exams.close();
name.close();
homework.close();
/*
A FOR Loop and a WHILE Loop have their exit condition
at the BEGINNING of the loop. It is possible that those
loops will NEVER execute because that exit condition is met
before the loop begins.
A DO WHILE Loop has its exit condition at the END Of the
loop. It will ALWAYS ALWAYS execute at least ONCE. No matter
what.
On the next exam, I WILL ask you the following question:
Name the three types of loops we have discussed this semester:
Which of those loops is fundamentally different from
the other two?
Why?
*/
system("pause");
return 0;
}
(It DOESN'T have to be professional)
Explanation / Answer
#include<iostream.h>
using namespace std;
int main()
{
ifstream homework, exams, name;
homework.open("hwgrades.txt");
exams.open("exgrades.txt");
name.open("student.txt");
float hwGrade,hwFGrade,exFGrade hwAvg=0;
float exGrade,TWGrade, exAvg=0;
string fName, lName;
float avg;
int hwCounter=0, exCounter=0;
if(homework==NULL)
cout<<"homework file not found";
while(!homework.eof())
{
homework >> hwGrade;
hwAvg = hwAvg + hwGrade;
hwCounter++;
}
hwAvg = hwAvg / hwCounter;
hwFGrade = hwAvg * .40;
if(exams==NULL)
cout<<"Exam file not found";
while(!exams.eof())
{
exams >> exGrade;
exAvg = exAvg + exGrade;
exCounter++;
}
exAvg = exAvg / exCounter;
exFGrade = wexAvg * .20;
name >> fName;
name >> lName;
cout << fixed << showpoint << setprecision(2);
TWGrade= (hwFGrade + exFGrade)/(hwCouunter * 40 + exCounter * 20);
cout << "Student Name: " << lName << ", " << fName << endl;
cout << "Homework Average: " << hwAvg << "%" << endl;
cout << "Exam Average: " << exAvg << "%" << endl;
cout<< "Grade is"<<TWGrade;
exams.close();
name.close();
homework.close();
system("pause");
return 0;
}
// Difference between a++ and ++a
a++:
In case a++ while using while loops or any other loops for the first iteration a will not be incremented.
Later from second iteration onwards a will be incremented.
EX:say a=1 initially
++a:In case ++a while using while loops or any other loops for the first iteration itself it will be incremented.
O/P: 2 3 4
EX:say a=1 initially do{ ++a; cout<<a; }while (a < 5); O/P: 2 3 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.