Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can someone help me with Task 3 please.. MH 1402 Task 3. (6 marks) Write a funct

ID: 3794480 • Letter: C

Question


can someone help me with Task 3 please..

MH 1402 Task 3. (6 marks) Write a function called merge.integer0 that merges two 3-digit integers numl and num2 (numl and num2 are two input parameters) into one integer. Suppose that num1 consists of three digits abe (each a, b, c represents one digit), num2 consists of three digits def (each d, e, f represents one digit), then numl and num2 are merged into 6-digit number adbecf. For example, if numl 123, num2 456, then numl and num2 are merged into 142536, Another example, if num! = 3, num2 = 456, then numl and num2 are merged into 40536. This function returns true if both numl and num2 are less than 1000; otherwise returns false. Global variable(s) should not be used in this function. 2 Write a main function to prompt a user to enter two th Write a main function to prompt a user to enter two three-digit positive integers less than 1000 (we assume that the user always enters positive integers), then call the function merge integer) to merge these two numbers. If the function merge integer() returns true, then print the merged number in the main function; otherwise, print "The inputs are not less than 1000" and terminate the program. Define the function merge integer() in the file task3.merge.cpp, and define the main function in the file task3.cpp. Task 4. (6 marks) 4 Write a function change.arr(). The inputs to this function are an int type array and the array size. This function finds the smallest and the second smallest values in the array, then replace the first element of the array with the smallest value, and

Explanation / Answer

Task3

/*
Program to read class object of employee from the key board and to
store it on a specified file using write() member functions finally
reading all objects using read() member function

write((char *) &objectname,sizeof(objectname))
read((char *) &objectname,sizeof(objectname))
*/

#include <fstream.h>
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#define MAX 20

class Employee
{
   protected:
       int eno;
       char ename[20],job[15];
       double sal,comm,np;
   public:
       Employee()
       {
           comm=0;
           np=0;
       }
       void getData();
       void dispData();
       void findComm();
       void findNp();
};

void Employee :: getData()
{
   cout << "Eployee no: "; cin >> eno;
   cout << "Employee name: "; cin >> ename;
   cout << "Employee job: "; cin >> job;
   cout << "Employee sal: "; cin >> sal;
}

void Employee :: dispData()
{
   cout << "No: " << eno << endl;
   cout << "Name: " << ename << endl;
   cout << "Job: " << job << endl;
   cout << "Salary: " << setprecision(3) << sal << endl;
   cout << "Comission: " << setprecision(3) << comm << endl;
   cout << "Netpay: " << setprecision(3) << np << endl;
}

void Employee :: findComm()
{
   if(strcmp(job,"Manager")==0)
   comm=0;
   else
   comm=sal * float(0.12);
}

void Employee :: findNp()
{
   np = sal + comm;
}

void main()
{
   clrscr();
   char fname[12];
   int n,i;
   Employee e[MAX];
   fstream f;
   cout << " Enter the file name: ";
   cin >> fname;
   f.open(fname,ios::in,ios::out);
   cout << " Enter no of records: ";
   cin >> n;

   cout << " Enter the employees information..! ";
   for(i=0; i<n; i++)
   {
       cout << endl << "Record: " << (i+1) << endl;
       e[i].getData();
       e[i].findComm();
       e[i].findNp();
   }
   f.open(fname,ios::out);
   cout << " Writing to the file....! ";
   for(i=0;i<n;i++)
   {
       f.write((char *) &e[i],sizeof(e[i]));
   }
   cout << endl << n << " Records written sucessfully....!";
   f.close();
   clrscr();
   //Reading the records from the file using read() member function
   f.open(fname,ios::in);
   cout << " Employee list....! " << endl;
   for(i=0;i<n;i++)
   {
       f.read((char *) &e[i],sizeof(e[i]));
       if(f.eof())
       break;
       e[i].dispData();
       cout << endl;
       getch();
   }
   f.close();
   getch();
}

Task 4:

//Using read() member function

#include <fstream.h>
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
#define MAX 200

class Employee
{
   protected:
       int eno;
       char ename[20],job[15];
       float sal,comm,np;
   public:
       void dispData();
};

void Employee :: dispData()
{
   cout << endl << "No: " << eno << endl;
   cout << "Name: " << ename << endl;
   cout << "Job: " << job << endl;
   cout << "Salary: " << setprecision(3) << sal << endl;
   cout << "Comission: " << setprecision(3) << comm << endl;
   cout << "Netpay: " << setprecision(3) << np << endl;
}

void main(void)
{
   clrscr();
   char fname[12];
   int j;
   Employee e[MAX];
   ifstream f;
   cout << " Enter the file name: ";
   cin >> fname;

   //Reading the records from the file using read() member function
   f.open(fname);
   cout << " Employee list....! ";
   j=0;
   while(1)
   {
       f.read((char *) &e[j],sizeof(e[j]));
       if(f.eof())
       break;
       e[j].dispData();
       getch();
       j++;
   }
   getch();
   f.close();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote