Couple additions

So I worked pretty hard on this code but I need to add a couple things to do that I have no idea how to do.

1) Here is the data given to me in a .txt
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
Wiley, Nicholas I.,9,23,97,0
Schwarz, Larry C.,64,18,47,0
Grimes, Linda R.,17,53,43,2
Brown, Ronald R.,53,63,85,1
Hines, Neil I.,3,49,68,0
Jain, David A.,92,85,83,1
Glass, Cindy L.,68,69,54,4
Fowler, Jacob O.,82,91,40,3
Schneider, Wanda C.,58,51,37,0
Gilbert, Edith I.,39,99,34,0
Parker, Nicole A.,60,88,44,0
Shaw, Cecil H.,37,9,19,0
Gold, Caroline O.,1,41,48,0
Monroe, John O.,64,6,12,2
McDowell, Steve C.,56,79,25,1
Sumner, William U.,59,51,98,3
Pugh, Francis U.,32,65,53,2
Crane, Gary R.,62,39,13,2
Stevens, Eleanor T.,7,42,82,0
Greer, Anne R.,5,54,20,0
McKay, Dana C.,30,86,21,0
Crawford, Pauline R.,49,21,9,1
Stephenson, James T.,19,92,63,1
Stark, Peter T.,27,43,98,1
Rodgers, Lucille O.,94,57,86,0


How do I take the code I already made and make it so it displays this information in the output instead?

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


#include <iostream>
#include <stdio.h>
#include <conio.h>

using namespace std;
class student
{
private :
	int sno;
	char name[20];
	double g1,g2,g3,g4;
	int absen;
public :
	void Getdata()
	{
		cout << "Enter Student ID:  "; cin >> sno; // User inputs their Student ID
		cout << "Enter Student NAME:  "; cin >> name; // User inputs the Studet Name
		cout << "Enter Student TEST SCORES (3):  "; cin >> g1 >> g2 >> g3; // User inputs the Test Scores
		cout << "Enter # of Absences:  "; cin >> absen; // User inputs how many absences
	}
	void Putdata()
	{
		cout  << "Student ID:  " << sno << endl; // displays Student ID
		cout << "Student NAME:  " << name << endl; // displays Student Name
		cout << "# of Absences:  " << absen << endl; // Displays # of Absences
		if (absen == 0) {
			g4 = 2;
		} else {
			g4 = 0;
		}
		cout << "Grade:  " << (g1+g2+g3 + g4)/3 << endl; // Displays Grade and if Successful/Unsuccessful
		if ((((g1+g2+g3 + g4)/3) >= 73))
		{cout << "Successful" << endl;}
		else
		{cout << "Unsuccessful" << endl;}
	};
};


int main()
{
	student s;
	s.Getdata();
	s.Putdata();
	getch();
	return 0;
}

Last edited on
So, you are trying to display the data that was given in the txt file?
I'm sorry I have a hard time understanding what questions are sometimes. I'm not sure I understand you.
Thanks
Yes, in an output that would display it like ..

Name( to first, middle, last):
Test Average:
Grade( this is something else I have to create so forget about this part for now)
Absences:
OK, if you are reading in from a file why are does it seem that you are having a user enter information in your code?
I'm not 100% sure. My thoughts on your question is that you could just use a structure and read into an array. I seems that your data is uniform in appearance so you might be able to do that.
You could just fill the array then display it. I'm not sure about all of your requirements for your assignment(or whatever) but that's my idea. I'm sure someone more experienced may have a better way to do it with an array.
I hope this helps you.
Do you have an example I could look off of when setting that up?
1
2
3
4
5
6
7
8
9
//Structure
struct infoType
{	
	string fname;
	string lname;
	string streetAdd;
	string cityStateZ;
	string phone;
};


Maybe read it in in like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Function to get info from file.
void readData(ifstream &fin, infoType tele[], int& size)
{	
	int i = 0;
	while(!fin.eof())
   {
		fin >> tele[i].fname;
		fin >> tele[i].lname;
		fin.get();
		getline(fin,tele[i].streetAdd,'\n');
		getline(fin,tele[i].cityStateZ,'\n');
		getline(fin,tele[i].phone,'\n');
	i++;
   }
		size = i;
}


I don't know maybe like this maybe someone has a better idea.
Topic archived. No new replies allowed.