Ok i have a problem which i cant seem to figure out why it is not woriking,
First off When i do Enter in some Details and want to enter Records to the end of File it give me the choice of enter in the Details.
When display the Array its only showing me the the Details i add to the End of the File.
And Also its not Add the Record to the end of the file
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
using namespace std;
struct Student
{
int student_number; //Student number
string student_firstname; //Students first Name
string student_lastname; //Students last Name
string Address; //Address of Student
int Date_Registered; //Date Registered
};
struct Course
{
string modules; //Student modules
int marks; //Marks of modules
};
int N_Module, j;
struct Course stArray1[6];
int N_STUDENT, i=0;
struct Student stArray[4];
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
int main ()
{
fstream myFile ("Student.text", ios::in | ios::out | ios::binary);
if (myFile.is_open())
{
N_STUDENT = -1;
do
{ cout << "Enter number of students less than 4" <<endl;
cin >> N_STUDENT;
cout << endl;
}
while(N_STUDENT > 4 || N_STUDENT<0);
for(i; i < N_STUDENT; i++)
{
cout << " Enter Student First Name: ";
cin >> stArray[i].student_firstname;
myFile << "STUDENT FIRST NAME:" << stArray[i].student_firstname;
cout << " Enter Student Last Name: ";
cin >> stArray[i].student_lastname;
myFile << "STUDENT LAST NAME:" << stArray[i].student_lastname;
cout << "Enter Student Address: ";
cin >> stArray[i].Address;
myFile << "STUDENT Address:" << stArray[i].Address;
N_Module = -1;
do
{ cout << "Enter number of Modules Taken less than 6" <<endl;
cin >> N_Module;
cout << endl;
}
while(N_Module > 6 || N_Module < 0);
for (j=0; j < N_Module; j++)
{
cout << "Enter Module Name: ";
cin >> stArray1[j].modules;
myFile << "Module Name:" << stArray1[j].modules;
cout << "Enter Module Marks: ";
cin >> stArray1[j].marks;
myFile << "Module Marks:" << stArray1[j].marks;
}
j=0;
}
myFile.close();
}
else cout << "Unable to open File";
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
//MENU
bool Exit = false;
while (!Exit)
{
int choice;
cout << endl;
cout << "=======================================" << endl;
cout << " " << endl;
cout << " WELCOME TO STUDENT RECORD " << endl;
cout << " " << endl;
cout << "=======================================" << endl;
cout << "Select Action: " << endl;
cout << "1) Display Student Details" << endl;
cout << "2) Add Student to End of File" << endl;
cout << "3) Sort Using Merge Sort" << endl;
cout << "4) Search Sorted Array Using Binary Search" << endl;
cout << "5) Add the Array to a Stack" << endl;
cout << "6) Display the Array" << endl;
cout << "7) Exit" <<endl;
cout << "=======================================" << endl;
cout << "Enter choice: ";
cin >> choice;
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
//DISPLAY THE ARRAY
if (choice == 1)
{
for(int i=0; i < N_STUDENT; i++)
{
cout << "Student First Name:" << " " << stArray[i].student_firstname << endl; //Read out Student Name
cout << "Student Second Name:" << " " << stArray[i].student_lastname << endl; //Read out Course Address
cout << "STUDENT Address: " << " " << stArray[i].Address << endl; //Read out Course Code
}
cout << " " << endl;
for (int j =0; j < N_Module; j++)
{
cout << "Module Name:" << stArray1[j].modules << endl;
cout << "Enter Module Marks:" << stArray1[j].marks << endl;
cout << " " << endl;
}
j=0;
}
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
// ADD STUDENT TO END OF FILE
else if (choice == 2 )
{
//int a;
//int b;
fstream myFile("Student.text", ios::app );
myFile.seekp(ios::end);
if(!myFile.good())
{
for(i =0; i < N_STUDENT; i++)
{
cout << " Enter Student First Name: ";
cin >> stArray[i].student_firstname;
myFile << "STUDENT FIRST NAME:" << stArray[i].student_firstname;
cout << " Enter Student Last Name: ";
cin >> stArray[i].student_lastname;
myFile << "STUDENT LAST NAME:" << stArray[i].student_lastname;
cout << "Enter Student Address: ";
cin >> stArray[i].Address;
myFile << "STUDENT Address:" << stArray[i].Address;
N_Module = -1;
do
{ cout << "Enter number of Modules Taken less than 6" <<endl;
cin >> N_Module;
cout << endl;
}
while(N_Module > 6 || N_Module < 0);
for (j; j < N_Module; j++)
{
cout << "Enter Module Name: ";
cin >> stArray1[j].modules;
myFile << "Module Name:" << stArray1[j].modules;
cout << "Enter Module Marks: ";
cin >> stArray1[j].marks;
myFile << "Module Marks:" << stArray1[j].marks;
}
j=0;
}
myFile.close();
}
}