Question

In: Computer Science

Q1(a) A class named “Employee” holds information like employee code, name,gender, year of joining. Write a...

Q1(a) A class named “Employee” holds information like employee code, name,gender, year of joining. Write a program in C++ to create three objects of employee and enter some data into it through setters. Make getters and setters for all employee information. Then ask the user to enter current year. Display the names of those employees whose tenure is 2 or more than 2 years according to the given current year only using getters

(b)A class named “Employee” holds information like employee code, name,gender, year of joining. Write a program to create five hundred objects (Array of employee objects )of employee and enter some data into it through setters. Make getters and setters for all employee information. Then ask the user to enter current year. Display the names of those employees whose tenure is 5 or more than 5 years according to the given current year only using getters.
Note: employee code is automatically assigned to newly created object by calling default constructor

(b) Define a class StudentReport with the following specification:
Private members :
adno 4 digit admission number
name 20 characters
marks an array of 5 floating point values
average average marks obtained
GETAVG() a function to compute the average obtained in five subject
Public members:
READINFO() function to accept values for adno, name, marks. Invoke the function   
GETAVG()

DISPLAYINFO() function to display all data members of StudentReport on the screen.
You should give function definitions outside the class using scope resolution operator.

Use C++ to answer

Solutions

Expert Solution

(a)

#include<iostream>
using namespace std;

class Employee{
       int code,yearjoin;
       string name,gender;
   public:
       int getCode()
       {
           return code;
       }
       int getYearjoin()
       {
           return yearjoin;
       }
       string getName()
       {
           return name;
       }
       string getGender()
       {
           return gender;
       }
       void setCode(int code)
       {
           this->code = code;
       }
       void setYearjoin(int yearjoin)
       {
           this->yearjoin = yearjoin;
       }
       void setName(string name)
       {
           this->name = name;
       }
       void setGender(string gender)
       {
           this->gender = gender;
       }
};

int main()
{
   Employee obj[3];
   obj[0].setCode(1001);
   obj[0].setYearjoin(1990);
   obj[0].setName("Mary");
   obj[0].setGender("F");
  
   obj[1].setCode(1002);
   obj[1].setYearjoin(2019);
   obj[1].setName("John");
   obj[1].setGender("M");
  
   obj[2].setCode(1003);
   obj[2].setYearjoin(2017);
   obj[2].setName("Mathew");
   obj[2].setGender("M");
  
   int cyear;
   cout<<"Enter current year: ";
   cin>>cyear;
  
   for(int i=0;i<3;i++)
   {
       if(cyear-obj[i].getYearjoin()>=2)
       {
           cout<<obj[i].getCode()<<"\t"<<obj[i].getName()<<"\t"<<obj[i].getGender()<<"\t"<<obj[i].getYearjoin()<<"\n";
       }
   }
}

================================================

(b)

#include<iostream>
using namespace std;

class Employee{
       int code,yearjoin;
       string name,gender;
   public:
       int getCode()
       {
           return code;
       }
       int getYearjoin()
       {
           return yearjoin;
       }
       string getName()
       {
           return name;
       }
       string getGender()
       {
           return gender;
       }
       void setCode(int code)
       {
           this->code = code;
       }
       void setYearjoin(int yearjoin)
       {
           this->yearjoin = yearjoin;
       }
       void setName(string name)
       {
           this->name = name;
       }
       void setGender(string gender)
       {
           this->gender = gender;
       }
};

int main()
{
   Employee obj[500];
   obj[0].setCode(1001);
   obj[0].setYearjoin(1990);
   obj[0].setName("Mary");
   obj[0].setGender("F");
  
   obj[1].setCode(1002);
   obj[1].setYearjoin(2019);
   obj[1].setName("John");
   obj[1].setGender("M");
  
   obj[2].setCode(1003);
   obj[2].setYearjoin(2017);
   obj[2].setName("Mathew");
   obj[2].setGender("M");
  
   /*
   if wanted enter more details
   */
  
   int cyear;
   cout<<"Enter current year: ";
   cin>>cyear;
  
   for(int i=0;i<500;i++)
   {
       if(cyear-obj[i].getYearjoin()>=5)
       {
           cout<<obj[i].getCode()<<"\t"<<obj[i].getName()<<"\t"<<obj[i].getGender()<<"\t"<<obj[i].getYearjoin()<<"\n";
       }
   }
}

//Output

==========================================

(c)

#include<iostream>
#include<cstring>
using namespace std;

class StudentReport{
   private:
       int adno;
       char name[20];
       float marks[5];
       float avg;
       float GETAVG();
   public:
       void READINFO(int adno, char name[], float marks[]);
       void DISPLAYINFO();
};

void StudentReport::READINFO(int adno, char n[], float marks[])
{
   this->adno = adno;
   strcpy(this->name,name);
   for(int i=0;i<5;i++)
   {
       this->marks[i] = marks[i];
   }
   avg = GETAVG();
}

float StudentReport::GETAVG()
{
   float sum = 0;
   for(int i=0;i<5;i++)
   {
       sum += marks[i];
   }
   sum/=5;
   return sum;
}

void StudentReport::DISPLAYINFO()
{
   printf("%d\t%s\t%f\n",adno,name,avg);
}


Related Solutions

Using C#: Write a class named Employee that has the following properties: Name - The Name...
Using C#: Write a class named Employee that has the following properties: Name - The Name property holds the employee's name IdNumber - The IdNumber property holds the employee's ID number Department - The Department property holds the name of the department in which the employee works Position - The Position property holds the employee's job title The class should have the following overloaded constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate...
in java, write code that defines a class named Cat The class should have breed, name...
in java, write code that defines a class named Cat The class should have breed, name and weight as attributes. include setters and getters for the methods for each attribute. include a toString method that prints out the object created from the class, and a welcome message. And use a constructor that takes in all the attributes to create an object.
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
C++ Design a class named TermPaper that holds an author's name, the subject of the paper,...
C++ Design a class named TermPaper that holds an author's name, the subject of the paper, and an assigned letter grade. Include methods to set the values for each data field and display the values for each data field. Create the class diagram and write the pseudocode that defines the class. Pseudocode help please
Write a class named RetailItem that holds data about an item in retail store.
Python 3Your program will have 2 classes:A) RetailItem ClassWrite a class named RetailItem that holds data about an item in retail store.Attributes: The class should store following data in attributes:>item_Name> PriceMethods:> RetailItem class’s __init__ method should accept an argument for each attribute.> RetailItem class should also have accessor and mutator methods for each attributeB) MainMenu ClassAttributes: The class should store following data in attributes:> List of RetailItem Objects: InventoryMethods:> createInventory(): method to create three RetailItem Objects store in list Inventory...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Develop a java program with a class named friend with data members like name, phno and...
Develop a java program with a class named friend with data members like name, phno and hobby. Use Parameterized constructor to create two friend objects and invoke checkhobby method which takes only one parameter, to find whether they have same hobby or different hobbies
Create a class named RemoveDuplicates and write code: a. for a method that returns a new...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new ArrayList, which contains the nonduplicate elements from the original list public static ArrayList removeDuplicates(ArrayList list) b. for a sentinel-controlled loop to input a varying amount of integers into the original array (input ends when user enters 0) c. to output the original array that displays all integers entered d. to output the new array that displays the list with duplicates removed Use this TEST...
Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT