Using an Input File

Write your question here.
Hello I am in second year of High School in Florida. I am taking a beginners computer class. As part of our final exam, my teacher said we have to work with C++. We have not used the program except to open it but she gave us an example of what the problem might look like when we have the exam. If anyone could help me put it together I would appreciate it. It's not an assignment that's due or anything but I want to know how to do it for my own peace of mind to be ahead of the class. We haven't learned how to code yet but I would like a head start.

Here is the example problem she gave us: "An instructor has asked you to write a program that can tell him if his students have passed or failed his course. He has a file that contains the following information":
* First name
* Last name
* Five quiz grades
* The midterm exam grade
* The final exam grade

Your program must read these values into variables then use those variables to calculate the final average and finally display that average to the screen.

Requirements:
1. Your program must calculate the final average including those quizzes. All the quizzes averaged together count as much as a test. So calculate the final quiz average, then average the midterm+final+quiz average.
2. Display the student's last name first, comma, space and first name. Follow that with the final average as a whole number, rounded up

Here's how it should appear on the output screen: ex.

Last name, First name average:87

I'm not sure that focussing upon a specific program at this point would be very useful. If you really want to get a head start, you could focus on getting a solid understanding of the fundamentals.

http://www.cplusplus.com/doc/tutorial/
The tutorial pages would be a good start, and with reference to file use, note at the bottom of that page, the sub-topic titled "Input/Output with files".

I read through the tutorial and it was very helpful. Thank you Chervil. I don't quite understand the language yet but i'm trying to get the concepts down. As for the example I gave above, I would like to understand how to do it and where to begin.
Start by laying out a basic, minimal program. For example, the hello world program without the hello world. Then try and go from there and post here when you get stuck.
This what I have so far:


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
  

include <iostream>
using namespace std;
int main()
{
int quizGrade1;
int quizGrade2;
int quizGrade3;
int quizGrade4;
int quizGrade5;
int midtermGrade;
int finalGrade;
double average;


cout << "82:";
cin >> quizGrade1;

cout << "71:";
cin >> quizGrade2;

cout << "65:";
cin >> quizGrade3;

cout << "72:";
cin >> quizGrade4;

cout << "81:";
cin >> quizGrade5;

cout << "95:";
cin >> midtermGrade;

cout << "90:";
cin >> finalGrade;


average = (quizGrade1+quizGrade2+quizGrade3+quizGrade4+quizGrade5+midtermGrade+finalGrade/7;


cout << "Your total average is: " << average << endl;


return 0;
}
The next stage is to compile it. The compiler helps you by displaying error messages for code which is invalid, as well as warnings for code which may be valid, but is possibly incorrect or unsafe.
Topic archived. No new replies allowed.