Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

21: Create a class called Rectangle that: (Ctrl + ) 1. Includes two private data members, length, and width (both of type int). 2. Provide

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
21: Create a class called Rectangle that: (Ctrl + ) 1. Includes two private data members, length, and width (both of type int). 2. Provide a member function named determineShape. Implement it outside the class to print if the shape is Square or Rectangle based on the length and width 3. Write a test program (i.e main function) that: creates two Rectangle objects * objl has length=3, and width = 3. obj2 has length = 4 and width = 5. For each object, determine if it is square or rectangle. . Q2: Creat a Class named Apartment with the following members: Private members: Name of Data Type Description member Area Double The area of the apartment CostPer Meter Double The cost of the square meter Region Char The region where the department is where A add 50 to the total cost B add 30 to the total cost add 10 to the total cost Floor Number Char The apartment floor number G Grand floor add 700 to the total cost First floor add 500 to the total cost Second floor add 200 to the total cost Public members: O A function SetInfo that will assign information to the data members. o A function Return Total that will retum the total cost of the apartment using the following equation Total cost - area * square meter cost + Region value + floor value o A function Print_total that takes the total cost and print out this cost. a) Write the program that implements class Apartment (don't write the implementation of the functions) b) Write the implementation of the function SetInfo. c) Write the implementation of the function Return Total. d) Write the implementation of the function Print total. 2) In the main function: Declare one object called MyFlat of class Apartment Input the following values for the object MyFlat The flat area is 200 m The cost per square meter is 120 D. It is in region B It is in the first floor Print out the total cost of this flat using the member function. o Q3: Define a class Point which is a three dimensional point having x, y and z coordinates. 1. Define a default constructor which initializes coordinates by 0. 2. Define a constructor to pass the coordinates values. 3. Define a destructor to print "you are out of the point. . . Q4: Create a class called Invoice that is used to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as private data members: A part number (type string), A part description (type string), A quantity of the item being purchased (type int) A price per item (type double). Your class should have a constructor that initializes the four data members. Provide a member function named getInvoiceAmount that calculates the invoice amount (ie., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates class Invoice's capabilities. Q5: Create a class called Employee that includes three pieces of information as private data members A first name (type string). A last name (type string). A monthly salary (type double). Your class should have a constructor that initializes the three data members. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10 percent raise and display each Employee's yearly salary again. Q6: Create a class called Date that includes three pieces of information as data members: A month (type int) A day (type int) A year (type int). Your class should have a constructor with three parameters that uses the parameters to initialize the three data members. Provide a member function displayDate that displays the month, day and year separated by forward slashes (). Write a test program that demonstrates class Date's capabilities. Q7: Consider a class emp, which is defined as shown: class emp int id; float salary: public: emp() (id =0; salary = -1; } void input (int c, float s) { id= c; salary: S; ????? 13 1) Define in main function an array allemp of 50 object of type emp. 2) Using a loop, in the main function write a code to change id and salary of the first 10 objects of the array to the values 100 and 500 respectively. 3) Replace the????? in the class definition with a member function which prints the id and salary of the objects. 4) Using a loop, in the main function write a code to print id and salary of the first 5 objects of the array, 5) Implement the access specifier protected in the class emp? Explain with example

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_2

Step: 3

blur-text-image_3

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

Define marketing.

Answered: 1 week ago

Question

What are the traditional marketing concepts? Explain.

Answered: 1 week ago

Question

Define Conventional Marketing.

Answered: 1 week ago

Question

Define Synchro Marketing.

Answered: 1 week ago