0% found this document useful (0 votes)
9 views

Coding

The document contains code for a C++ program that manages employee award records. It defines functions to open a file, add records, list records, search records, update records, delete records, and save records to a file. The main function contains a menu to call these functions and manage the award records.

Uploaded by

nurirdinabk22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Coding

The document contains code for a C++ program that manages employee award records. It defines functions to open a file, add records, list records, search records, update records, delete records, and save records to a file. The main function contains a menu to call these functions and manage the award records.

Uploaded by

nurirdinabk22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

const int maxrow = 10;

string EmpDate [maxrow] = {};

string EmpAward [maxrow] = {};

string EmpRf [maxrow] = {};

string EmpAav [maxrow] = {};

void OpenFile()

string line;

ifstream dina("Award.txt");

if (dina.is_open())

int x = 0;

while (getline(dina, line))

int l = line.length();

EmpDate[x]= line.substr(0, 3);

EmpAward[x]= line.substr(4, 1 - 4);

EmpRf[x] = line.substr();

EmpAav[x] = line.substr();

x++;

else
{

cout << "Unable to open the file!" << endl;

void AddRecord()

char date[50];

char award[100];

char rf[50];

char aav[50];

cin.ignore();

cout << "Date:";

cin.getline(date,50);

cout << "Award / Achievement:";

cin.getline(award,100);

cout << "Recieved from:";

cin.getline(rf,50);

cout << "Academic Advisor Verification:";

cin.getline(aav,50);

for (int x = 0; x < maxrow; x++)

if (EmpDate[x] == "\0")

EmpDate[x] = date;

EmpAward[x] = award;

EmpRf[x] = rf;

EmpAav[x] = aav;
break;

void ListRecord()

system("CLS");

cout << "Current Record(s)" << endl;

cout <<
"=================================================================================
=====================================" << endl;

int counter = 0;

cout << "No.| Date | Award / Achievement | Recieved from | Academic Advisor Verification | "
<< endl <<
"----------------------------------------------------------------------------------------------------------------------\n";

for (int x = 0; x < maxrow; x++)

if (EmpAward[x] != "\0")

counter++;

cout << " " << counter << " " << EmpDate[x] << " "<< EmpAward[x] << " " << EmpRf[x] << " "
<< EmpAav[x] << endl;

if (counter == 0)

cout << "No Record Found!" << endl;

}
cout << "====================================" << endl;

void SearchRecord(string search)

system("CLS");

cout << "Current Record(s)" << endl;

cout << "====================================" << endl;

int counter = 0;

for (int x = 0; x < maxrow; x++)

if (EmpDate[x] == search)

counter++;

cout << " " << counter << " " << EmpDate[x] << " "<< EmpAward[x] << " " << EmpRf[x] << " "
<< EmpAav[x] << endl;

break;

if (counter == 0)

cout << "No Record Found!" << endl;

cout << "===================================" << endl;

void UpdateRecord(string search)

char date[50];
char award[50];

char rf[50];

char aav[50];

int counter = 0;

for (int x = 0; x < maxrow; x++)

if (EmpDate[x] == search)

counter++;

cout << "Award / Achievement: ";

cin.getline(award, 50);

EmpAward[x] = award;

cout << "Update Successfull!" << endl;

break;

if (counter == 0)

cout << "Date does not EXIST!" << endl;

void DeleteRecord(string search)

int counter = 0;
for (int x = 0; x < maxrow; x++)

if (EmpDate[x] == search)

counter++;

EmpAward[x] = "";

EmpDate[x] = "";

cout << "Successfully Deleted!" << endl;

break;

if (counter == 0)

cout << "Date does not EXIST!" << endl;

void SaveToFile()

ofstream dina;

dina.open("Award.txt", ios :: app);

for (int x = 0; x < maxrow; x++)

if (EmpDate[x] == "\0")

break;

}
else

dina << EmpDate[x] + "," + EmpAward[x] + "," + EmpRf[x] + "," + EmpAav[x] << endl;

int main()

std::cout << "MENU\n";

int option;

string EmpDate;

system("CLS");

OpenFile();

do

cout << "1-Fill in award." << endl;

cout << "2-Update award" << endl;

cout << "3-Delete award" << endl;

cout << "4-Search Award" << endl;

cout << "5-Display all awards" << endl;

cout << "6-Save and Exit" << endl;

cout << "================================" << endl;

cout << "Select option >>";

cin >> option;

switch (option)

case 1: AddRecord();
system("CLS");

break;

case 2:

cin.ignore();

cout << "Search by Date >>";

getline(cin, EmpDate);

UpdateRecord(EmpDate);

system("CLS");

break;

case 3:

cin.ignore();

cout << "Delete by Date >>";

getline(cin, EmpDate);

DeleteRecord(EmpDate);

cin.ignore();

system("CLS");

break;

case 4:

cin.ignore();

cout << "Search by Date >>";

getline(cin,EmpDate);

SearchRecord(EmpDate);

break;

case 5: ListRecord();

break;

case 6:
cout << "Data saved and exit";

while (option != 6);

SaveToFile();

cout << "Exit and Saving to file!" << endl;

return 0;

You might also like