I haven't been around coding in a long time, and I decided to get back into it so I can website design, one of the assignments I did last year, I got and knew what to do for one of my last years classes, and I tried to do it again to get my bearings back on this subject :p. But I can't seem to remember how to do it. In short, the programs needs to be able to average out any number of grades that you enter in, in a menu like setting. I'm not asking anyone to do my work, because I want to understand how to do it myself. I just need some hints as to how to conquer this problem.
It's basically a menu system that allows you to set number of grades then enter them manually, which takes them and averages them out. I also remember that you can write to at txt file as well. Of course the switch statement is used too when called up the menu items as well.
This is what I got so far...
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice;
int grades
int NUMBER_OF_GRADES = 1;
int GRADES_ENTERED = 2;
int GENERATE_RANDOM = 3;
int READ_FROM_TXT = 4;
int WRITE_TO_TXT = 5;
// Menu
cout << "(1) Set the number of grades ";
cout << "(2) Enter the grades manually";
cout << "(3) Generate random grades";
cout << "(4) Read the grades from the Grades.txt file";
cout << "(5) Write the grades to the Grades.txt file ";
cout << "Menu selection (1-5) : "
cin >> choice;
cout << fixed << showpoint << setprecision(2)
if (choice == NUMBER_OF_GRADES)
{
cout << "How many grades? ";
cin >> grades
system("Pause");
return 0;
}
Check out the time.h library for random numbers. For file input/output, you can use the fstream library. You can solve the whole assignment using loops, user input/output, and file input/output. I've just provided the guidelines for the problem. Look for tutorials for each of the items I have stated if you cannot remember them. Otherwise, if you have any more problems along the way, I'll be glad to help.
This is what I got so far, I looked into the tutorials more, and I get what they are saying, and you for the input/output file, as well as the use for fstream, but still, I'm confused on how I would combine the two, with multiple functions. But here's what I got, I also written some comments as to what I did in the past to make it work.
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace std;
int setNumberOfGrades()
{
int grades;
cout << "Number of Grades (1-5): ";
cin >> grades;
while (grades <=0)
{
cout << "Please enter a valid number (1-5): "
cin >> grades;
}
elseif (grades == 1)
{
grades
// Don't know what to add in here to have grades show up on a counter
}
int calcAverage(
// Not sure how to add it into the main
int enterGrades()
{
int
//Can't work from here unless I do the first section
int main()
{
int choice;
constint NUMBER_OF_GRADES = 1;
GRADES_ENTERED = 2;
GENERATE_RANDOM = 3;
READ_FROM_TXT = 4;
WRITE_TO_TXT = 5;
// Menu
cout << "(1) Set the number of grades ";
cout << "(2) Enter the grades manually";
cout << "(3) Generate random grades";
cout << "(4) Read the grades from the Grades.txt file";
cout << "(5) Write the grades to the Grades.txt file ";
cout << "Menu selection (1-5): "
cin >> choice;
cout << fixed << showpoint << setprecision(2)
if (choice == NUMBER_OF_GRADES)
{
// Would need to do the setNumberOfGradesFunction
system("Pause");
return 0;
}
// Layout of program
// Variables
//setNumberOfGrades
//Between 1 and 5 are allowed
//enterGrades
// Grades from counter and setNumberOfGrades
// Enter each grade manually
//randomGrades
// Generates random grades in the counter
//readGrades
// Reads grades from a txt file called grades.txt
//writeGrades
// Writes grades to a txt file called grades.txt
// calcAverage
// Reads the grades from //entergrades and averages them out ( divide by 5)
// Puts in Grade Average counter
// clearGrades
// Function that resets the grades when you use //setNumberOfGrades
// or if you entered a new set of grades
//mainProgram
int grades;
cout << "Number of Grades (1-5): ";
cin >> grades;
while (grades <=0)
{
cout << "Please enter a valid number (1-5): "
cin >> grades;
}
What are you trying to do with this? If you are trying to get the number of grades then one cin>>grades would be enough. Why are you getting the grades again in a while loop?
// Don't know what to add in here to have grades show up on a counter
What counter? Do you mean the menu?
1 2 3
// clearGrades
// Function that resets the grades when you use //setNumberOfGrades
// or if you entered a new set of grades
You can call this function and just take the values for the grades variables again. This will just overwrite the previous values.
1 2 3
// calcAverage
// Reads the grades from //entergrades and averages them out ( divide by 5)
// Puts in Grade Average counter
Use parameters for the calcAverage function.
1 2 3 4 5
//readGrades
// Reads grades from a txt file called grades.txt
//writeGrades
// Writes grades to a txt file called grades.txt