Student Database File Data Troubles
how would the full display look with these functions |
Try it and see. I haven't looked through and compiled your entire program.
how would i reference these functions in the main during my menu function |
You will have to create a student object and call the member functions.
1 2
|
Student myStudent;
myStudent.setLastName(Name);
|
how would i add new student data via inputs to the file and be able to be saved and still displayed when i wish it |
Use an outstream to add new data to 'database.txt'. This process is called 'save and restore'
Last edited on
i dont understand how this would work though i fee l like it would just read the same line of text as the first name function
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
|
void setLastName(string lName)
{
fstream database;
database.open("database.txt");
string textLine;
do
{
getline (database, textLine);
if (textLine == lName)
break;
} while (!database.eof());
if (textLine == lName)
cout<< "Last Name :" << lName << endl;
else
cout << "There is no such last name!";
}
string getLastName() const
{ return lName; }
|
also where would i put the function calls for the member functions you describe above
here is my current main.cpp:
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
|
#include <iostream>
#include <string>
#include <cstring>
#include "student.h"
#include <fstream>
#include <iomanip>
using namespace std;
const string user = "grader";
const string password = "12345";
void adminLogin();
void Menu();
int main()
{
adminLogin();
return 0;
}
void adminLogin()
{
string name, pass;
cout << " CSU " << endl;
cout << " Adminsitrator Login " << endl;
cout << "-------------------------------------------" << endl;
cout << "Username: ";
cin >> name;
cout << "Password: ";
cin >> pass;
if (name == user & pass == password)
{
cout << "\nYou are logged in!";
Menu();
}
else
{
cout << "\nInvalid Username and/or Password..." << endl;
adminLogin();
}
}
void Menu()
{
string menuChoices[] = {"Display Student Records", "Search Student(first name)", "Exit Program"};
for(int z=0; z<3; z++)
{
cout << z+1 << "\t\t" << menuChoices[z] << endl;
}
int userChoice;
cout << "(Please enter a number) :";
cin >> userChoice;
switch (userChoice)
{
case 1:
// Display entire student database here
break;
}
}
|
Topic archived. No new replies allowed.