Hello everybody, this is my first post in a forum like these so sorry if i'm not completely clear about some things. I'm trying to build a system for a kids playcentre. Everything seemed to have been runing pretty smoothly apart from this.
What I am trying to do, is to read the contents of a text file so that the user can then edit the file within the console program. I can read the contents of the text file, However I am unable to edit it correctly. This is all for an assignment which is due in May.
E.g. 1. The user should be able to select option 5 to add an employee.
2. The user should then be able to select option 7 to view the records within the file.
3. The user should then be able to select option 6 to edit a specific record.
My thoughts initially are to open the file and then use STD::string to do the actual editing. Taking a string from the user and then comparing it to text in the file and replacing if necessary. However, I am completely stumped as to how to begin this.
Many thanks to everyone in advance, please let me know if I can be of any more assistance.
Any help with this would be much apprieciated.
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <iostream>
#include<fstream>
#include<sstream>
#include<conio.h>
#include<stdio.h>
#include<iomanip>
#include<string>
using namespace std;
/////////////////////////////
//////CLASS EMPLOYEE///////////////
class Employee
{
private:
int EmployeeID, EmployeeFirstName, EmployeeLastName;
double Wage;
public:
void AddEmployee()
{
string EmployeeID, EmployeeFirstName, EmployeeLastName;
double Wage=0.00;
ofstream fout;
fout.open("EmployeeRecord.txt",ios::app); // open file for appending
cout<<"Enter Employee ID: ";
cin >> EmployeeID;
cout << "\n";
cout<<"Enter Employee First Name: ";
cin >> EmployeeFirstName;
cout << "\n";
cout<<"Enter Employee Last Name: ";
cin >> EmployeeLastName;
cout << "\n";
cout<<"Enter Employee Wage: ";
cin >> Wage;
fout << setiosflags(ios::fixed | ios :: showpoint)
<< setprecision(2);
fout<< EmployeeID<< ", " << EmployeeFirstName
<< " " << EmployeeLastName<< " , " << Wage << endl;
fout << fixed;
fout.close( ); //close file
;
}
};
//////////////////////////////////////
//////VIEW EMPLOYEE ON RECORD/////////
void ViewEmployeeRecord()
{
string line;
ifstream x ("EmployeeRecord.txt");
if (x.is_open())
{
while(!x.eof())
{
cout<<endl;
getline(x,line);
cout<<line<<endl;
}
x.close();
}
else
cout<<"Cant open file."<<endl;
}
/////////////////////////////
//////FUNCTION MENUSCREEN///////////////
void MenuScreen()
{
loop:
cout << "\n\nPlease select what you would like to do\n\n";
cout << "[1] Add a new customer\n\n";
cout << "[2] Edit an existing customer\n\n";
cout << "[3] Make a party booking\n\n";
cout << "[4] edit a party booking\n\n";
cout << "[5] Add a new employee\n\n";
cout << "[6] edit a current employee\n\n";
cout << "[7] View employee's on record\n\n";
int selection;
cin>>selection;
cout<<""<<endl;
if (selection==1)
{
system("cls");
cout << "You have selected option 1\n\n";
system("cls");
goto loop;
}
else if (selection==2)
{
system("cls");
cout << "You have selected option 2\n\n";
system("cls");
goto loop;
}
else if(selection==3)
{
system("cls");
cout << "You have selected option 3\n\n";
system("cls");
goto loop;
}
else if(selection==4)
{
system("cls");
cout << "You have selected option 4\n\n";
system("cls");
goto loop;
}
else if(selection==5)
{
system("cls");
cout << "You have selected option 5 to add a new employee\n\n";
Employee NewEmployee;
NewEmployee.AddEmployee();
goto loop;
}
else if(selection==6)
{
system("cls");
cout << "You have selected option 6 to edit an employee\n\n";
system("cls");
goto loop;
}
else if(selection==7)
{
system("cls");
cout << "You have selected option 7 to view employees on record\n\n";
ViewEmployeeRecord();
goto loop;
}
else
{
cout<<"Invalid! Try again."<<endl;
goto loop;
}
}
/////////////////////////////
///////MAIN///////////////
int main ()
{
MenuScreen();
cout << "Press any key to continue\n";
char response;
cin >> response;
return 0;
}
|