C++ TEST!

Guys I have a test right now and I haven't studied. Please help me out?

heres the question:

write a program that reads information for 3 students. The information to be read is Name, Id and total mark. The mark is out of 100. The program calculates the average mark and prints out the information and the average. In the last 4 lines the data should be aligned correctly, the marks and the average should be printed with two decimals.

Sample:
enter student information
Name? Ben
ID? 2088374
Mark? 90
Enter second student information
Name? John
ID? 1231231
Mark?89
Enter third student information
Name? Alex
ID? 1231241
Mark?69
Ben 123123123 90
John 12312312 89
Alex 12312333 69
The average mark is: 74.67


Exercise 2:
modify the program written in exercise 1 so that you read the student information from the file info.txt and save the output in output.txt They should look like this:

Input:
Ben 123123123 90
John 123123123 75
Alex 1231233 69

Output:
Ben 123123123 90
John 123123123 75
Alex 123123123 59
The average mark is: 74.67

(The output part is supposed to be aligned)

THANKS!
Last edited on
Hehe, I think I must have missed the question..What was the question again? I am not a great programmer but i am a google master..If I knew what you was asking.
hackphreak wrote:
Guys I have a test right now and I haven't studied. Please help me out?
I can't think of a person here who would do this.
worth a shot :P
when do u have to finish it?
here is a good out "My dog ate my computer" that always works for me ;)
in case u do still need it im almost done with the first part
BettyBoopTS wrote:
here is a good out "My dog ate my computer" that always works for me ;)
Considering how many tutors/lecturers we have out there that seem incompetent. I wonder if anyone has ever truly believed something like that. Unless of course you have something like what I once had - a rabbit chew all your computer cables. Still wasn't a valid excuse :)
,,, writing,,, 'My pot belly pig, Mr Bigglesworth chewed my computer cables"
Genius Mythios! absolute genius!! ;)
Haha :D
Here's the first part
Editing it 5 more minutes
Last edited on
in case u do still need it im almost done with the first part
That must be one long test, to go on for more than four hours
lol I started with my first post
Last edited on
Now I really Finished Part 1
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
#include <iostream>
using namespace std;
int main()
{
	char Name1 [15];
	char Name2 [15];
	char Name3 [15];
	int ID1;
	int ID2;
	int ID3;
	float Mark1;
	float Mark2;
	float Mark3;
	cout<<"Enter The First Students Information\n";
	cout<<"Name: ";
	cin>>Name1;
	cout<<"ID: ";
	cin>>ID1;
	cout<<"Mark: ";
	cin>>Mark1;
	if (Mark1>100) {
		cout<<"Invalid Entry";
		cin.ignore();
		cin.get();
		return 0;}
	cout<<"Enter The Second Students Information\n";
	cout<<"Name: ";
	cin>>Name2;
	cout<<"ID: ";
	cin>>ID2;
	cout<<"Mark: ";
	cin>>Mark2;
	if (Mark2>100) {
		cout<<"Invalid Entry";
		cin.ignore();
		cin.get();
		return 0;}
	cout<<"Enter The Third Students Information\n";
	cout<<"Name: ";
	cin>>Name3;
	cout<<"ID: ";
	cin>>ID3;
	cout<<"Mark: ";
	cin>>Mark3;
	if (Mark3>100) {
		cout<<"Invalid Entry";
		cin.ignore();
		cin.get();
		return 0;}
	cout<<Name1<<" "<<ID1<<" "<<Mark1<<"\n";
	cout<<Name2<<" "<<ID2<<" "<<Mark2<<"\n";
	cout<<Name3<<" "<<ID3<<" "<<Mark3<<"\n";
	float Average=(Mark1+Mark2+Mark3)/3;
	cout<<"The Average Mark is "<<Average;
	cin.ignore();
	cin.get();
}
Well, at least it's not any less god awful than OP could have written it.
what do u mean?
closed account (jLNv0pDG)
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
	cout<<"Enter The First Students Information\n";
	cout<<"Name: ";
	cin>>Name1;
	cout<<"ID: ";
	cin>>ID1;
	cout<<"Mark: ";
	cin>>Mark1;
	if (Mark1>100) {
		cout<<"Invalid Entry";
		cin.ignore();
		cin.get();
		return 0;}

	cout<<"Enter The Second Students Information\n";
	cout<<"Name: ";
	cin>>Name2;
	cout<<"ID: ";
	cin>>ID2;
	cout<<"Mark: ";
	cin>>Mark2;
	if (Mark2>100) {
		cout<<"Invalid Entry";
		cin.ignore();
		cin.get();
		return 0;}

	cout<<"Enter The Third Students Information\n";
	cout<<"Name: ";
	cin>>Name3;
	cout<<"ID: ";
	cin>>ID3;
	cout<<"Mark: ";
	cin>>Mark3;
	if (Mark3>100) {
		cout<<"Invalid Entry";
		cin.ignore();
		cin.get();
		return 0;}


That could be simplified with a FOR loop.
lol good point
Topic archived. No new replies allowed.