C++ Assignment help (help me)

I am confused about this assignment question, please guide me.
Questions :
In this assignment, students are required to create a small program that is able to read in any inputs from the text files provided and perform operations using the texts as described.

  1. A set of figures (profiles_figures.txt) which record profiles of employees of a company
    The structure of the record is arranged based on attributes such as employee ID, date of birth, height, weight, years of working in the company, basic salary and also allowances.
  2. A set of strings (profiles_words.txt) which record profiles of employees of a company
    The structure of the record is arranged based on attributes such as employee name, country, designation, gender and level of education.

In this program, each of the members is responsible of three modules:
Member Modules Description
1 Add User is able to add new details of an employee.
Select User is able to read the information of the employees selected from any attributes. E.g., if user keys in ‘i’ or ‘mi’ under name attribute, the outputs must be able to display the information of all employees which his/her name (e.g., ‘Suhaimi’, ‘Smith’, ‘Philip’, ……) contains ‘i’ or ‘mi’ in any position.
Standard Deviation User is able to select any attributes (height, weight, ……) of all employees to calculate the standard deviation.
2 Delete User is able to delete the selected employee.
AdvanceSearch User is able to search and display the details of selected employees using different combination of attributes to further filter the search results. E.g. if he/she selects 3 attributes with the combination of name, employee ID and height, the search results will be refined based on these attributes. He/she can select more than or less than 3 attributes in the new search.
Average User is able to select any attributes (height, weight, ……) of all employees to calculate the average.

Students are required to complete their assignment as below:

  1. This is a menu-driven program; create a menu selection for the user to select the modules.
  2. Each module is represented with a function.
  3. All the modules must be able to perform operations with the two types of inputs.
  4. The functions are limited to necessary operation. COUTs and FUNCTION CALLs are only allowed in the MAIN function.
  5. Each member must involve functions with RETURN TYPE and REFERENCE PARAMETER for their own modules.

Hello! Welcome to the forum!

What’s your question :slight_smile:?

Hi Sir, my question is regarding C++ programming.
In this assignment, students are required to create a small program that is able to read in any inputs from the text files provided and perform operations using the texts as described.

  1. A set of figures (profiles_figures.txt) which record profiles of employees of a company
    The structure of the record is arranged based on attributes such as employee ID, date of birth, height, weight, years of working in the company, basic salary and also allowances.
  2. A set of strings (profiles_words.txt) which record profiles of employees of a company
    The structure of the record is arranged based on attributes such as employee name, country, designation, gender and level of education.
    In this program, each of the members is responsible of three modules:
    |Member|Modules|Description|
    |—|---|—|
    |1|Add|User is able to add new details of an employee.|
    ||Select|User is able to read the information of the employees selected from any attributes. E.g., if user keys in ‘i’ or ‘mi’ under name attribute, the outputs must be able to display the information of all employees which his/her name (e.g., ‘Suhaimi’, ‘Smith’, ‘Philip’, ……) contains ‘i’ or ‘mi’ in any position.|
    ||Standard Deviation|User is able to select any attributes (height, weight, ……) of all employees to calculate the standard deviation. |
    |2|Delete|User is able to delete the selected employee. |
    ||AdvanceSearch|User is able to search and display the details of selected employees using different combination of attributes to further filter the search results. E.g. if he/she selects 3 attributes with the combination of name, employee ID and height, the search results will be refined based on these attributes. He/she can select more than or less than 3 attributes in the new search.|
    ||Average|User is able to select any attributes (height, weight, ……) of all employees to calculate the average.|

Students are required to complete their assignment as below:

  • This is a menu-driven program; create a menu selection for the user to select the modules.
  • Each module is represented with a function.
  • All the modules must be able to perform operations with the two types of inputs.
  • The functions are limited to necessary operation. COUT s and FUNCTION CALL s are only allowed in the MAIN function.
  • Each member must involve functions with RETURN TYPE and REFERENCE PARAMETER for their own modules.

Help me Sir…

We aren’t going to do the assignment for you, but we are happy to help you improve the code you have been working on or discuss trouble spots.

3 Likes

#include
#include
#include<stdio.h>

using namespace std;

//Employee class Declaration
class Employee{
private:
int code;
char name[20];
float salary;
public:
void read();
void display();
//will return employee code
int getEmpCode() { return code;}
//will return employee salary
int getSalary() { return salary;}
//will update employee salary
void updateSalary(float s) { salary=s;}
};

//Read employee record
void Employee::read(){
cout<<"Enter employee code: ";
cin>>code;
cout<<"Enter name: ";
cin.ignore(1);
cin.getline(name,20);
cout<<"Enter salary: ";
cin>>salary;
}

//Display employee record
void Employee::display()
{
cout<<code<<" “<<name<<”\t"<<salary<<endl;
}

//global declaration
fstream file;

//Will delete file when program is being executed
//because we are create file in append mode
void deleteExistingFile(){
remove(“EMPLOYEE.DAT”);
}

//function to append record into file
void appendToFille(){
Employee x;

//Read employee record from user
x.read();
 
file.open("EMPLOYEE.DAT",ios::binary|ios::app);
if(!file){
    cout<<"ERROR IN CREATING FILE\n";
    return;
}
//write into file
file.write((char*)&x,sizeof(x));
file.close();
cout<<"Record added sucessfully.\n";

}

void displayAll(){
Employee x;

file.open("EMPLOYEE.DAT",ios::binary|ios::in);
if(!file){
    cout<<"ERROR IN OPENING FILE \n";
    return;
}
while(file){
if(file.read((char*)&x,sizeof(x)))
    if(x.getSalary()>=10000 && x.getSalary()<=20000)
        x.display();
}

file.close();
}

void searchForRecord(){
//read employee id
Employee x;
int c;
int isFound=0;

cout<<"Enter employee code: ";
cin>>c;


file.open("EMPLOYEE.DAT",ios::binary|ios::in);
if(!file){
    cout<<"ERROR IN OPENING FILE \n";
    return;
}
while(file){
    if(file.read((char*)&x,sizeof(x))){
        if(x.getEmpCode()==c){
            cout<<"RECORD FOUND\n";
            x.display();
            isFound=1;
            break;
        }
    }
}
if(isFound==0){
    cout<<"Record not found!!!\n";
}
file.close();

}

//Function to increase salary
void increaseSalary(){
//read employee id
Employee x;
int c;
int isFound=0;
float sal;

cout<<"enter employee code \n";
cin>>c;


file.open("EMPLOYEE.DAT",ios::binary|ios::in);
if(!file){
    cout<<"ERROR IN OPENING FILE \n";
    return;
}
while(file){
    if(file.read((char*)&x,sizeof(x))){
        if(x.getEmpCode()==c){
            cout<<"Salary hike? ";
            cin>>sal;
            x.updateSalary(x.getSalary()+sal);
            isFound=1;
            break;
        }
    }
}
if(isFound==0){
    cout<<"Record not found!!!\n";
}
file.close();
cout<<"Salary updated successfully."<<endl;

}

//Insert record by assuming that records are in
//ascending order
void insertRecord(){
//read employee record
Employee x;
Employee newEmp;

//Read record to insert
newEmp.read();

fstream fin;
//read file in input mode
file.open("EMPLOYEE.DAT",ios::binary|ios::in);
//open file in write mode
fin.open("TEMP.DAT",ios::binary|ios::out);

if(!file){
    cout<<"Error in opening EMPLOYEE.DAT file!!!\n";
    return;
}
if(!fin){
    cout<<"Error in opening TEMP.DAT file!!!\n";
    return;
}
while(file){
    if(file.read((char*)&x,sizeof(x))){
        if(x.getEmpCode()>newEmp.getEmpCode()){
            fin.write((char*)&newEmp, sizeof(newEmp));
        }
        //no need to use else
        fin.write((char*)&x, sizeof(x));
    }
}

fin.close();
file.close();
 
rename("TEMP.DAT","EMPLOYEE.DAT");
remove("TEMP.DAT");
cout<<"Record inserted successfully."<<endl;

}

int main()
{
char ch;

//if required then only remove the file
 deleteExistingFile();

 do{
 int n;

 cout<<"ENTER CHOICE\n"<<"1.ADD AN EMPLOYEE\n"<<"2.DISPLAY\n"<<"3.SEARCH\n"<<"4.INCREASE SALARY\n"<<"5.INSERT RECORD\n";
 cout<<"Make a choice: ";
 cin>>n;

 switch(n){
      case 1:
        appendToFille();
        break;
      case 2 :
        displayAll();
        break;
      case 3:
        searchForRecord();
        break;
    case 4:
        increaseSalary();
        break;
    case 5:
        insertRecord();
        break;

      default :
            cout<<"Invalid Choice\n";
 }

 cout<<"Do you want to continue ? : ";
 cin>>ch;

 }while(ch=='Y'||ch=='y');
 
return 0;

}

Im stuck at this