Anda di halaman 1dari 3

Assignment 2

Object Oriented Programing


Topic: structures & classes

Total Marks: 100

Due Date: 2nd April 2017 11:59:59pm

Instructions
1. Attempt all questions.
2. Copy/Cheating is STRICTLY PROHIBITED. If anyone caught doing cheating simply whole
assignment will be canceled.
3. You can discuss assignment questions with other students but write your OWN code. Don’t
share your code with anyone.
4. Late submission will cause 50% deduction of marks.
5. Best of luck 

struct Product

string description; // Product description

int partNum; // Part number

double cost; // Product cost

};

Question # 1 Write a definition for an array of 100 Product structures. Do not initialize the array.

Question # 2 Write a loop that will step through the entire array you defined in Question 11.4, setting
all the product descriptions to an empty string, all part numbers to zero, and all costs to zero.

Question # 3 Write the statements that will store the following data in the first element of the array
you defined in Question 1:

Description: Claw hammer

Part Number: 547

Part Cost: $8.29

Question # 4 Write a loop that will display the contents of the entire array you created in Question 1.
struct Rectangle

int length;

int width;

};

Question # 5 Write a function that accepts a Rectangle structure as its argument and displays the
structure’s contents on the screen.

Question # 6 Write a function that uses a Rectangle structure reference variable as its parameter
and stores the user’s input in the structure’s members

Question # 7 Write a function that returns a Rectangle structure. The function should store the
user’s input in the members of the structure before returning it.

Question # 8 Write the definition of a pointer to a Rectangle structure.

Question # 9 Assume rptr is a pointer to a Rectangle structure. Which of the expressions, A, B, or C,


is equivalent to the following expression:

rptr->width

A) *rptr.width

B) (*rptr).width

C) rptr.(*width)

Question # 10 What are accessors and mutators?

Question # 11 An object’s private member variables are accessed from outside the object by

A) public member functions

B) any function

C) the dot operator

D) the scope resolution operator


Question # 12 Complete the following code skeleton to declare a class named Date . The class should
contain variables and functions to store and retrieve a date in the form 27/3/2017.

class Date

private:

public:

Question # 13 What is the advantage of inline function?

Question # 14 What is constructer and destructor? When they are called? Why can’t we have more
than one default constructer and a destructor? Write the purpose of destructor.

Question # 15 Number Array Class

Design a class that has an array of floating-point numbers. The constructor should accept an integer
argument and dynamically allocate the array to hold that many numbers. The destructor should free the
memory held by the array. In addition, there should be member functions to perform the following
operations:

• Store a number in any element of the array

• Retrieve a number from any element of the array

• Return the highest value stored in the array

• Return the lowest value stored in the array

• Return the average of all the numbers stored in the array

Demonstrate the class in a program.

Anda mungkin juga menyukai