Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve all questions, write using basic C++ functions 1. When class B is inherited from class A, what is the order in which the destructor

solve all questions, write using basic C++ functions image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1. When class B is inherited from class A, what is the order in which the destructor of those classes are executed A. Class A first Class B next C. Class B's only as it is the child class B. Class B first Class A next D. Class A's only as it is the parent class 2. If a class Demo1 has a pure virtual function named f, and class Demo2 inherits from Demo1, then, which of the following is correct A. It is optional for Class Demo2 to define the implementation of function f1 B. A user can define an object instance from class Demo1 C. It is optional for Class Demo1 to define the implementation of function f1 D. Class Demo2 cannot be inherited. 3. One of the following is correct A. Static member functions can access class member variables but non-static cannot B. You can call a static member function using object instance or using class name C. Non-static functions cannot access static class variables D. You can call a non-static member function using object instance or using class name 4. The default access level assigned to members of a class is A. Private C. Protected B. Public D. Needs to be assigned 5. For which type of class private and protected members of the class can be accessed from outside the same class in which they are declared A. No such class exist C. Static B. Friend D. Virtual 6. Having a member function defined as int f1 (int x, int y ) const means A. The function f1 cannot change x or y B. The function f1 cannot return a value that is based on calculations of class member variables C. The function f1 cannot change the class member variables D. The function f1 cannot change any value iniside, it only returns 7. The advantage of defining a member function as int f1 (const A&x ) A. Guarantees that the passed object x is not changed within the function B. Allows quick parameter passing by passing the object value by reference C. No advantages D. A and B 8. Inside a function definition for a member function of an object with data element x, which of the following is equivalent to this->x: A. ( this) x C. x B. "this->x D. Both A and C are correct Each city has a name, number of residents ( ), and average yearly income() per resident. class City f public: City (string name, int numResident, float avgincome); city (): float GetCityIncome () ; private: string name; float income ; int numResidents ; \} ; Write the implementation of the following functions: A. GetCitylncome function. This computes the total yearly income of the city according to the given income and number of residents. ( 4 points) B. Overload the + operator such that it allows combing two cities into one new city object. The combination should reflect the merging of two cities including the name, income and number of residents. Note that the average income of the combination should reflect correctly for the total of the two merged cities. The name should include both names. (7 points) C. Overload the > operation to compare between the two city objects and return true if the left city has more income. ( 5 points) A company has a computer system that has five subsystems. The company has three types of employees Accountant (), HR ( ), and Admin (). Each employee has permissions () to access one or more of the five subsystems based on his/her employment type. The company offers salaries based on the employee type and rank with base salary computed based on rank. Given the following two classes: Assume that all member functions (non-virtual) defined in both classes are implemented. Define a new class called Accountant. This class should 1. Inherit (derive) from Employee class and include one new int member variable ( years of experience). (6 points) 2. Define a constructor to initialize all member variables (rank, name, years of experience) (6 points) 3. Implement the GetPermissions function such that the Accountants have access to the first two subsystems only (sys 1 , and sys 2 ). (6 points) 4. Implement the GetSalary function such that for each rank, the accountant receives 150JD in addition to the base salary that is given to all employees. The ranks will be 1,2,3, or 4 . (6 points) Assume that the classes for Permissions and Employee are all implemented correctly. Also, assume that the classes for Accountant, Admin, and HR are implemented correctly with an initializer constructor for each class receives (rank, name), and also each class has implemented GetSalary and GetPermissions functions. 1) Write a non-member function Employee * ReadEmployee() which takes no parameters and returns a pointer to an Employee object. The function asks the user to enter employee information as the following: rank, name, type where rank could be 1,2,3, or 4 and type is 1 for Accountant, 2 for HR, and 3 for Admin. Your function should create and set an object of the appropriate type according to the user input and return a pointer to it. ( 6 points) 2) Write a main function that: A. Defines an array of employee pointers with size 1000. (4 points) B. Read 1000 employee objects using ReadEmployee function done before and store them in the array. ( 3 points) C. Print the salaries of the 1000 employees. (3 points) D. Read 100 requests of employees requesting to get permissions to access one of the subsystems, out of these 100 requests, print the total number of valid request (valid request means the employee has access to that requested subsystem). Requests comes in the following format: Employee name, subsystem number ex. Ahmad, 2 means employee Ahmad is requesting to access subsystem 2. Assume that employees' names are unique (no repetition in names) (8 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

What types of cables are commonly used in wired LANs?

Answered: 1 week ago