Help with c++ Homework please

Good evening (night time here), I am fairly new to c++, however I have little knowledge on java, my professor for c++ gave us a 7 part project and I need help in question 3. What my program is supposed to do is to read and display, delete, update, delete a specific record and write the records into a new text file, however my problem is with the updating a specific record. I think I could use another switch statement to work with the selection of student record to edit, however other than that I think I need some kind of loop to find the student and select the student file and be able to change it's values and save it into the array [k] for that file, that's were I need help with, also please tell me if this is an ok way to store data, or am I messing it up worse? so far the other cases work for me (1,2,4,5,6) for this part 4 question I have part of my code...

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

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main()

{int k=0;
int i=1;
short select2=0;
ifstream inFile("inputData.csv");
ofstream outFile("output1.txt");
if(!inFile.is_open())
{
cout << "ERROR READ: input File is Open."<<'\n';
}
if(!outFile.is_open())
{
cout << "ERROR READ: output File is Open."<<'\n';
}

string firstname;
string lastname;
string ID;
string email;
string street;
string city;
string state;
string zipcode;
string telephone;
string exam1;
string exam2;
string exam3;
string Ffirstname[50];
string Llastname[50];
string IID[50];
string EEmail[50];
string Sstreet[50];
string Ccity[50];
string Sstate[50];
string Zzipcode[50];
string Ttelephone[50];
string Eexam1[50];
string Eexam2[50];
string Eexam3[50];

short select1;
cout<<"1.-Create Student Record.\n2.-Display Student Record.\n3.-Update Student Record.\n4.-Delete Student Record.\n5.-Display and Write Student Records.\n6.-Exit.\n";
cin>>select1;
(start of switch cases 1,2,4,5,6)
.....
.....
case 3:
cout<<"which student record would you like to update?\n";
cin>>select2;// select 2 is used for the new switch statement to choose the student records to be updated (values changed).
while(!inFile.eof())
{
getline(inFile,firstname,',');
getline(inFile,lastname,',');
getline(inFile,ID,',');
getline(inFile,email,',');
getline(inFile,street,',');
getline(inFile,city,',');
getline(inFile,state,',');
getline(inFile,zipcode,',');
getline(inFile,telephone,',');
getline(inFile,exam1,',');
getline(inFile,exam2,',');
getline(inFile,exam3,'\n');
if(inFile.eof()) break;

Ffirstname[k]=firstname;
Llastname[k]=lastname;
IID[k]=ID;
EEmail[k]=email;
Sstreet[k]=street;
Ccity[k]=city;
Sstate[k]=state;
Zzipcode[k]=zipcode;
Ttelephone[k]=telephone;
Eexam1[k]=exam1;
Eexam2[k]=exam2;
Eexam3[k]=exam3;
cout<<Ffirstname[k]<<"\n"<<Llastname[k]<<"\n"<<IID[k]<<"\n"<<EEmail[k]<<"\n"<<Sstreet[k]<<"\n"<<Ccity[k]<<"\n"<<Sstate[k]<<"\n"<<Zzipcode[k]<<"\n"<<Ttelephone[k]<<"\n"<<Eexam1[k]<<"\n"<<Eexam2[k]<<"\n"<<Eexam3[k]<<"\n\n";
k++;
}
...
...
else if (select1>6)//6=number of cases in menu.
{
cout<<"Please try again later.";
exit(0);
}

inFile.close();
outFile.close();
}
You could read the complete file into an array, update a particular record and write the complete array into a new file.

Another option would be to read line by line and check if it needs updated. Update if necessary and write it into the new file.

BTW: Haven't you learned about structs and functions ?
that's my last step (add a class, extra credit), I will post it tomorrow if I can't handle it, I will try it tomorrow and let you know. Thank you for the pointers.
Topic archived. No new replies allowed.