Final programming c++ | Computer Science homework help

 

//Classes(or Libraries)

#include <iostream>

#include <string>

#include <fstream>

#include <sstream>

#include <iomanip>

//Used to shorten console commands

using namespace std;

 

//Programmer defined encapsulation of data and functions

class Department

{

private:

string  DepartmentName, DepartmentHeadName, DepartmentID;

 

public:

// Constructors

    Department()

{

 

}

Department(string id, string name)

{

DepartmentID = id;

DepartmentName = name;

DepartmentHeadName = “”;

}

Department(string id, string name, string hn)

{

DepartmentID = id;

DepartmentName = name;

DepartmentHeadName = hn;

}

 

    //Setter and getters(Accsesors)

    string getDepId()

{

return DepartmentID;

}

string getDepartmentName()

{

return DepartmentName;

}

string getDepHeadName()

{

return DepartmentHeadName;

}

 

 

void setDepId(string DepId)

{

 

DepartmentID = DepId;

}

 

void setDepName(string DepName)

{

 

DepartmentName = DepName;

}

void setDepHead(string DepHead)

{

 

DepartmentHeadName = DepHead;

 

}

 

 

 

};

 

//Programmer defined encapsulation of data and functions 

class Employee

{

private:

string employeename, employeeID, employeeDepartmentID;

int employeeage;

doubleemployeesalary;

public:

 

    // constructors

    Employee() {}

Employee(string id, string name)

{

employeeID = id;

employeename = name;

}

Employee(string id, string name, int age)

{

employeeID = id;

employeename = name;

employeeage = age;

}

Employee(string id, string name, int age, double salary)

{

employeeID = id;

employeename = name;

employeeage = age;

employeesalary = salary;

 

}

Employee(string id, string name, int age, double salary, string departmentid)

{

employeeID = id;

employeename = name;

employeeage = age;

employeesalary = salary;

employeeDepartmentID = departmentid;

}

 

// Accessors

    string getEmpID()

{

return employeeID;

}

string getEmpName()

{

return employeename;

}

 

string getEmpDepID()

{

return employeeDepartmentID;

}

int getEmpAge()

{

return employeeage;

}

double getEmpSal()

{

return employeesalary;

}

void setEmpID(string empId)

{

 

employeeID = empId;

}

void setEmpName(string empName)

{

 

employeename = empName;

}

void setEmpDepID(string empDepId)

{

 

employeeDepartmentID = empDepId;

}

void setEmpAge(int empAge)

{

 

employeeage = empAge;

}

void setEmpSalary(double empsal)

{

 

employeesalary = empsal;

}

 

 

};

 

//Function prototypes

void ShowMenu();

void choices();

 

int main()

{

 

ShowMenu();

choices();

 

return 0;

}

 

//Display Function

void ShowMenu()

{

    cout << “nnn”;

cout << “1-Create Departmentn”;

cout << “2-Creat employeen”;

cout << “3-Write the data to the filen”;

cout << “4-Retrive the data from the filen”;

cout << “5-Display Reportn”;

cout << “6-Exitn n n”;

}

 

// Choice function

void choices()

{

// Creating array objects

    Department dep[3];

Employee emp[7];

 

    string depid, empid, empdepid, depname, dephead, empname, depnamefile, depdeadfile;

int empage; 

double empsalary;

int choice;

ifstream file_in, file_in2;

ofstream file_out, file_out2;

char again; //Used to loop the entire program

int counter, empcounter, depcounter;

bool id3 = false;

int a; //used for getting age from file

double s; //used for getting salarry from file

string info; // getting lines from file

size_t pos; //position

double sal1, sal2, sal3; //Salaries for calculation

 

 

do {

cout << “Please enter a number from the menu:”;

cin >> choice;

 

 

switch (choice)

{

case 1:

 

cout << “Please enter Department ID:”;

cin >> depid;

 

            //Loop to not get a duplicate

            for (int i = 0; i < 3; i++)

{

while (dep[i].getDepId() == depid)

{

cout << “The Department ID that you entered exist. Try again:”;

cin >> depid;

 

}

}

 

                //Condition to make sure not over arrays

if (depcounter < 3)

{

cout << “Please enter the department name:”;

cin >> depname;

 

cout << “Please enter the department head:”;

cin >> dephead;

 

dep[depcounter].setDepId(depid);

dep[depcounter].setDepName(depname);

dep[depcounter].setDepHead(dephead);

depcounter++;

}

else

cout << “Array is full.n”;

 

ShowMenu();

 

break;

 

case 2:

 

 

cout << “Please enter the employee ID:”;

cin >> empid;

 

            //Loop to not get duplicate

            for (int i = 0; i < 7; i++)

{

while (emp[i].getEmpID() == empid)

{

cout << “The Employee ID that you entered exist. Try again:”;

cin >> empid;

}

}

 

                //condition to not go over arrays sizes

if (empcounter < 7) {

 

cout << “Please enter the employee department ID:”;

cin >> empdepid;

for (int i = 0; i < 7; i++)

{

if (dep[i].getDepId() == empdepid)

{

id3 = true;

break;

}

 

}

if (id3)

{

cout << “Please enter the employee Name:”;

cin >> empname;

 

cout << “Please enter the employee Age:”;

cin >> empage;

 

cout << “Please enter the employee salary:”;

cin >> empsalary;

 

emp[empcounter].setEmpID(empid);

emp[empcounter].setEmpName(empname);

emp[empcounter].setEmpDepID(empdepid);

emp[empcounter].setEmpAge(empage);

emp[empcounter].setEmpSalary(empsalary);

empcounter++;

}

else

cout << “Department not foundn”;

}

else

cout << “Array is full.n”;

 

 

ShowMenu();

break;

case 3:

 

            //condition to mmake sure objects are compelted, the write to file

                

            if (depcounter == 3 && empcounter == 7)

{

file_out.open(“dep.txt”);

 

for (int counter = 0; counter < 3; counter++)

{

file_out << “Department ID: ” << dep[counter].getDepId() << endl;

file_out << “Department Name: ” << dep[counter].getDepartmentName() << endl;

file_out << “Department Head Name: ” << dep[counter].getDepHeadName() << endl;

file_out << endl << endl;

 

}

 

file_out.close();

 

file_out2.open(“emp.txt”);

 

for (int counter = 0; counter < 7; counter++)

{

file_out2 << “Employee ID: ” << emp[counter].getEmpID() << endl;

file_out2 << “Employee Name: ” << emp[counter].getEmpName() << endl;

file_out2 << “Employee Age: ” << emp[counter].getEmpAge() << endl;

file_out2 << “Employee Salary: ” << emp[counter].getEmpSal() << endl;

file_out2 << “Employee Department ID: ” << emp[counter].getEmpDepID() << endl;

file_out2 << endl << endl;

 

}

 

 

                //Making sure user doesn’t close the program without saving data

cout << “File not saved. Do you want to save the file? (Y/N)n”;

cin >> again;

if (toupper(again) == ‘Y’)

file_out.close();

file_out2.close();

}

else

cout << “Arrays not complete. Can’t write into files.n” << endl << endl;

 

 

ShowMenu();

break;

case 4:

 

 

file_in.open(“dep.txt”);

 

 

 

if (file_in)

{

int counter;

// getting department data from file

                while (getline(file_in, info) && counter < 3)

{

pos = info.find(“: “);

dep[counter].setDepId(info.substr(pos + 2));

getline(file_in, info);

pos = info.find(“: “);

dep[counter].setDepName(info.substr(pos + 2));

getline(file_in, info);

pos = info.find(“: “);

dep[counter].setDepHead(info.substr(pos + 2));

getline(file_in, info);

getline(file_in, info);

counter++;

}

file_in.close();

 

}

else cout << “File Dep not found.” << endl;

 

 

 

file_in2.open(“emp.txt”);

 

 

if (file_in2)

{

int counter;

//getting employee data from file

                while (getline(file_in2, info) && counter < 7)

{

pos = info.find(“: “);

emp[counter].setEmpID(info.substr(pos + 2));

getline(file_in2, info);

pos = info.find(“: “);

emp[counter].setEmpName(info.substr(pos + 2));

getline(file_in2, info);

pos = info.find(“: “);

istringstream flow(info.substr(pos + 2));

flow >> a;

emp[counter].setEmpAge(a);

getline(file_in2, info);

pos = info.find(“: “);

istringstream flow1(info.substr(pos + 2));

flow1 >> s;

emp[counter].setEmpSalary(s);

getline(file_in2, info);

pos = info.find(“: “);

emp[counter].setEmpDepID(info.substr(pos + 2));

getline(file_in2, info);

getline(file_in2, info);

counter++;

}

file_in2.close();

}

else cout << “File Emp not found.” << endl;

 

ShowMenu();

break;

 

case 5:

 

 

            //Linear search through arrays

for (int i = 0; i < 7; i++)

{

if (emp[i].getEmpDepID() == dep[0].getDepId())

{

sal1 = sal1 + emp[i].getEmpSal();

}

if (emp[i].getEmpDepID() == dep[1].getDepId())

{

sal2 = sal2 + emp[i].getEmpSal();

}

if (emp[i].getEmpDepID() == dep[2].getDepId())

{

sal3 = sal3 + emp[i].getEmpSal();

}

 

}

//displaying report

            cout << showpoint << fixed << setprecision(2);

            cout << “DepartmenttSalaryreportn”;

cout << dep[0].getDepartmentName() << “tt” << sal1 << “n”;

cout << dep[1].getDepartmentName() << “tt” << sal2 << “n”;

cout << dep[2].getDepartmentName() << “tt” << sal3 << “n”;

 

ShowMenu();

break;

 

case 6:

 

cout << “Exiting the program. Thank you.” << endl;

 

break;

 

default:

cout << “Invalid selection. Please Try again” << endl;

 

ShowMenu();

break;

 

 

 

 

 

 

}

} while (choice != 6);

}

 

 

 

The purpose of this project is to take your Midterm project  and  implement it using Random Access Binary Files.  

As you recall, the Midterm project used text files to store the data. Here in the final exam project, 

you will be storing the data in Random Access Binary File. 

 

Also, in the Midterm project you used Arrays to temporarily hold the data in the memory until the user

decides to write the data to file. Here you will not be using Arrays and instead writing the 

data directly to Random Access Binary File. Please read the chapter Advance File and I/O operations 

before attempting this. 

 

Here is the full description of the Final exam project. 

 

Modify your Midterm Exam Project to:

 

1. Replace  Employee and Department classes with Employee and Department Structures.

 

2. Inside each structure, replace all string variables with  array of characters.

 

3. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. 

 

4. Do not allow the user to edit the Employee ID and Department ID. 

 

5. Use Random Access Files to store the data in Binary Form. This means, you should not use an Arrays to

store the data in the memory. Instead, when the user wants to create a new Employee/Department, 

you write it to the file right away. Also when the user says he/she wants to edit 

an Employee/Department, ask the user to enter EmployeeID/DepartmentID. 

Read the data from the file and display it to the user. 

Allow the user to enter new data and write it back to the file in the same position inside the file. 

Please read the chapter . Advance File/IO operations which has examples on how to do this.

Calculate your paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Quality Papers

We value our clients. For this reason, we ensure that each paper is written carefully as per the instructions provided by the client. Our editing team also checks all the papers to ensure that they have been completed as per the expectations.

Professional Academic Writers

Over the years, our Acme Homework has managed to secure the most qualified, reliable and experienced team of writers. The company has also ensured continued training and development of the team members to ensure that it keep up with the rising Academic Trends.

Affordable Prices

Our prices are fairly priced in such a way that ensures affordability. Additionally, you can get a free price quotation by clicking on the "Place Order" button.

On-Time delivery

We pay strict attention on deadlines. For this reason, we ensure that all papers are submitted earlier, even before the deadline indicated by the customer. For this reason, the client can go through the work and review everything.

100% Originality

At Buy An Essay, all papers are plagiarism-free as they are written from scratch. We have taken strict measures to ensure that there is no similarity on all papers and that citations are included as per the standards set.

Customer Support 24/7

Our support team is readily available to provide any guidance/help on our platform at any time of the day/night. Feel free to contact us via the Chat window or support email: support@acmehomework.com.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Buy An Essay has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.

Essays

Essay Writing Services

At Buy An Essay, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.

Admissions

Admission and Business Papers

Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.

Editing

Editing and Proofreading

Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.

Coursework

Technical papers

We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.