Averages and Random Grades

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;




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
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;
}

Last edited on
closed account (EvoTURfi)
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.
K thanks, thats sweet :), I'll see what I can do
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.




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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace 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;
	}
	else if (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;

	const int  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 
closed account (EvoTURfi)
1
2
3
4
5
6
7
8
	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 


ifstream and ofstream. Look them up.

Anymore help?
Last edited on
Topic archived. No new replies allowed.