Assistance with C++ Writing a code

Write your question here.



Hi All,
I'm almost halfway through the semester and so far so good, they give us one week to write a program, however, my 70 year old mother was in a car accident last week, and honestly, I had not even opened the assignments (online class) until today. Of course, I have to write a program that is due before midnight and I don't even know where to begin.

I would be very grateful if someone can assist.

Here is the assignment:

The logic needed here is complex!!! Pseudo code your logic first then work one piece of the code at a time, Don't forget to ensure the validity of the input.

Create a program to handle a college class grades:

Capture the Teacher's name
Capture the Class designation
The program should ask how many students are in the class and do the following for each student:
Read the students name
Read in up to 10 grades for the student (from 0 - 100 is acceptable. If outside the range don't use the input, ask for a correction , 999 should stop input of grades if there are less than 10)
Calculate the average of the student's grades
Compute the student's grade as a letter grade
For the entire class
Compute the class's grade average
Determine how many A's, B's, C's, D's and F's are in the class.
Write the following data to a file called class_statistics.txt

Teacher: Bob Marley
Class: CGS1010
Student Name: Jim Beam Average: 88 Grade: B
Donna Jenner 95 A
Student count: 2
Student average: 91.5
A's: 1
B's: 1
C's: 0
D's: 0
F's: 0


Thank you!

Diana
"The logic needed here is complex!!!" Lol, I really hope you aren't a CS major. Post the code you have so far, then I'll attempt to help you, so will others.
Last edited on
That was quoted by the teacher, and it is a class that I choose to learn more about, however, as a virtual class, it is very hard to follow.
Oh, I thought you posted that lol. Yea just post the code you have already. All you need to do is get input and do minor minor calculations. This should be a very easy to write
That is the problem I am having all I have so far is this: I don't even know where to start and I don't even know if it is right.

#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

void printFileToScreen();

int main()

cout << "Teacher name: Bob Marley" <<endl;
cout << "Class: CGS1010" <<endl;
He also said to use this:

#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

void printFileToScreen();

int main()
{
//close the input file here
printFileToScreen();
return 0;
}

void printFileToScreen()
{
ifstream inData;
string line = "";
inData.open("class_statistics.txt");
while(inData)
{
getline(inData,line);
cout << line << endl;
}
inData.close();
}
Put code in codetags (highlight the code and hit the <> button on the right) and make sure you post all your code
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

void printFileToScreen();

int main()

cout << "Teacher name: Bob Marley" <<endl;
cout << "Class: CGS1010" <<endl;

//close the input file here
printFileToScreen();
return 0;
}

void printFileToScreen()
{
ifstream inData;
string line = "";
inData.open("class_statistics.txt");
while(inData)
{
getline(inData,line);
cout << line << endl;
}
inData.close();
}
Not sure if I did that right, I'm exhausted from being in hospital all day, I can barely see straight!! LOL thank you for taking the time to assist.
Put code in codetags by highlighting your text that is code and pressing the <> button
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
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

void printFileToScreen();

int main()

cout << "Teacher name: Bob Marley" <<endl;
cout << "Class: CGS1010" <<endl;

//close the input file here
printFileToScreen();
return 0;
}

void printFileToScreen()
{
ifstream inData;
string line = "";
inData.open("class_statistics.txt");
while(inData)
{
getline(inData,line);
cout << line << endl;
}
inData.close();
}
You need to post your code like this or no one will help you on this site but I'll try to address some things to help you out.. Don't even worry about printFileToScreen function for now, you aren't even using it. Focus on getting the main parts of your program working first. Looks like you need to get input from the user and ask how many students are in the class. Do you know how to do that?
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
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

void printFileToScreen();

int main()

cout << "Teacher name: Bob Marley" <<endl;
cout << "Class: CGS1010" <<endl;

//close the input file here
printFileToScreen();
return 0;
}

void printFileToScreen()
{
ifstream inData;
string line = "";
inData.open("class_statistics.txt");
while(inData)
{
getline(inData,line);
cout << line << endl;
}
inData.close();
}
Last edited on
no :(
You need to first ask how many students are in the class like your programming assignment says.. For this you need something like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
#include <iomanip>
#include<iostream>
using namespace std;

int main()
{

	//Vars
	int numberOfStudents = 0;

	cout << "Teacher name: Bob Marley" << endl;
	cout << "Class: CGS1010" << endl;

	cout << "\n How many students are in the class?"; cin >> numberOfStudents;
	return 0;
}
Ok so then my question would be is how would the program know from the students which ones to take. In his example he has two students, but if we leave that open, and let's say we don't have those students defined, then how would the program know?
BTW thank you so much for being patient. I work for an airline, if you ever need a buddy pass you can email me (it's a small airline so hopefully it flies from your nearest airport)
Maybe this will help you get started.. Can you finish the rest?

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
#include<iostream>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<string>
#include<vector>
using namespace std;

//Global
int aStudentAvg = 0;
string aStudentGrade = "";

void letterGrade(int num)
{
	if (num >= 0 && num <= 59)
		aStudentGrade = "F";

	if (num > 59 && num <= 69)
		aStudentGrade = "D";

	if (num > 69 && num <= 79)
		aStudentGrade = "C";

	if (num > 79 && num <= 89)
		aStudentGrade = "B";

	if (num > 89 && num <= 100)
		aStudentGrade = "A";
}

int main()
{

	//Vars
	int numberOfStudents = 0;
	vector<int> studentGrades;
	vector<string> studentNames;
	vector<int> studentAverages;

	//Ask how many students are in the class?
	cout << "\nHow many students are in the class? "; cin >> numberOfStudents;

	//Read in the student's name and the student's grade
	for (int i = 0; i < numberOfStudents; i++)
	{
		//Store student name and grades in temporary variable 
		string tempStudent;
		string tempGrade;

		//Store the student name in a vector
		cout << "Enter the name for student # " << (i + 1) << ": "; cin.ignore(); getline(cin, tempStudent);
		studentNames.push_back(tempStudent);

		//Loop through 10 grades
		for (int j = 0; j < 10; j++)
		{
			//Store the student grade in a vector (and convert it to a integer so we can do calculations on it)
			cout << "Enter the grades for the student " << "(" << (j+1) << ")" << ": "; cin >> tempGrade;
			studentGrades.push_back(stoi(tempGrade));
		}

		//Get the student's average
		for (int k = 0; k < studentGrades.size(); k++)
		{
			//Sum up all grades
			aStudentAvg += studentGrades[k];
		}

		//To hold a student's average 
		aStudentAvg = aStudentAvg / (studentGrades.size());
		
	}

	//Get Letter Grade
	letterGrade(aStudentAvg);

	//Display the student's average grade.
	cout << endl;
	cout << "Teacher: Bob Marley" << endl;
	cout << "Class: CGS101" << endl;
	cout << "Student Name: " << studentNames[0] << " Average: " << aStudentAvg << " (" << aStudentGrade << ")" << endl;
	cout << "Student Count: " << numberOfStudents;
	cout << endl;

	//End of Program
	return 0;
}


I had fallen asleep, just got home from work.

I think so let me try.

Thank you!!
Topic archived. No new replies allowed.