this is for a school ok?
i wanna to do some thing that if person press 1 start to add student and when press EOF something like 999 or -1 finish the entering... beside that, i wanna to save this on a file in order that if he/she press number 3 and chose to search by name or lname... be able to find student from the file. but every time i start to add new student it replaced to the last student :/
to sum up:
1- i don't know how to add names over and over in the file without losing last data
2- i don't know how to search in the file by the name or lname :(
oh i have number 3 too: i don't know how to delete a information of a student that i have entered already
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
class NewStudent{
public:
string Name,Lname,Major,Location;
int Grade=0,Age=0;
};
int Adder = 0;
NewStudent STU[255];
int New(){
for(Adder;Adder< 55;Adder++){
cout << "Please Enter The Name Of The Student: ";
cin >>STU[Adder].Name;
cout << "Please Enter The Last Name Of The Student: ";
cin >>STU[Adder].Lname;
cout << "Please Enter The Age Of The Student: ";
cin >> STU[Adder].Age;
cout << "Please Enter The Location Of The Student: ";
cin >>STU[Adder].Location;
cout << "Please Enter The Major Of The Student: ";
cin >>STU[Adder].Major;
cout << "Please Enter The Grade Of The Student: ";
cin >> STU[Adder].Grade;
ofstream fout ("output.txt");
fout << STU[Adder].Name << "," << STU[Adder].Lname << "," << STU[Adder].Age
<< "," << STU[Adder].Location << "," << STU[Adder].Major << ","
<< STU[Adder].Grade << endl;
fout.close();
cout << "\nYour Student Have Bean Saved";
}
}
int Delete(){
}
Fiind(){
cout << "You have Name(1) Or Lastname(2)";
int chose;
cin >> chose;
switch(chose)
{
case 1:
{
cout << "\n\nYou Have Name. So Please Enter The Name of Student That You Want" <<endl;
int n = STU.name.size();
for (int i=0;i<=n;i++)
break;
}
case 2:
{
cout << "\n\nYou Have Name. So Please Enter The Last Name of Student That You Want" <<endl;
break;
}
}
}
int Average(){
}
int main()
{
int chose;
cout << "(1) -> Enter New Student. "
<< "\n(2) -> Delete A Student. "
<< "\n(3) -> Ask For Information Of a Student. "
<< "\n(4) -> Ask For Numbers Of a Computer Student"
<< "\n(5) -> Ask For Numbers Of how many lives in esf\n"
<< "\nPlease Select One Of Numbers > ";
cin >> chose;
switch(chose)
{
case 1:
{
cout << "\n\nEnter New Student." <<endl;
New();
cout << "\n\n" << endl;
main();
break;
}
case 2:
{
cout << "\n\nDelete A Student." <<endl;
Delete();
break;
}
case 3:
{
cout << "\n\nAsk For Information Of a Student." <<endl;
Fiind();
break;
}
case 4:
{
cout << "\n\nAsk For Numbers Of a Computer Student." <<endl;
break;
}
case 5:
{
cout << "\n\nAsk For Numbers Of how many lives in esf." <<endl;
break;
}
}
return 0;
}
Student sudents[255];
int student_count = 0;
//<Read one students or more>
std::ofstream fout ("output.txt", std::ios::app);
for(int i = 0; i < student_count; ++i)
//<Write students>
2)
1 2 3 4 5
std::ifstream fin(/*...*/);
Student student;
do {
student = //Read student from in
} while(student.name != /*name we want*/)
1 2 3 4 5 6 7
std::ifstream fin(/*...*/);
std::ofstream fout(/*...*/);
while(fin) {
Student student = //Read student from in
if (/*record is not one to delete*/)
//write student to fout.
}
Another approach would be read all students to array and make changes/search here.
int chose;
cin >> chose;
NewStudent Student;
switch(chose)
{
case 1:
{
cout << "\n\nYou Have Name. So Please Enter The Name of Student That You Want";
ifstream fin('output.txt', ios::app);
do {
STU = fin >> output.txt;
}while(Student.Name != jack)
break;
}
Is It Going to Next Recoerd???????how to search by the name and going to next record from my file?
this is have error an my code::block :/
error: 'jack' was not declared in this scope|
error: 'output' was not declared in this scope|
error: expected ';' before 'break'|
error: no match for 'operator>>' in 'fin >> "output.txt"'|
i really think about that and i don't know how to make this well :(
its really hard to understand what it dose.. how to read file . .. how to put fully main arrey in a new array to study about that...
how to know is read all main array... :(
It seems that you are still struggling with basics. I suggest refresh your knowledge on basic info like variables, strings, loops, arrays, functions, etc. before you go to more advanced topics.