You are on page 1of 2

OOP Questions Ctt

1. Construct a class named Circle that contains two integer data members named xCenter and yCenter, and a floating point data member named radius. Additionally, the class should contain a static data member named scaleFactor. Here the xCenter and yCenter values represent the center point of a circle, radius represents the circles actual radius, and scaleFactor represents a scale factor that will be used to scale the circle to fit on a variety of display devices. 2. Write a program which reads a sequence of integers and counts how many there are. Print the count. For example, with input 55 1000 20 4 -6 55 0 55, the output should be 8 because there were eight numbers in the input stream. Your program should work for any input, not just this example.

3. Write a class called CAccount which contains two private data elements, an integer accountNumber and a floating point accountBalance, and three member functions: i. A constructor that allows the user to set initial values for accountNumber and accountBalance and a default constructor that prompts for the input of the values for the above data members. ii. A function called inputTransaction, which reads a character value for transactionType ('D' for deposit and 'W' for withdrawal), and a floating point value for transactionAmount, which updates accountBalance. iii. A function called printBalance, which prints on the screen the accountNumber and accountBalance.
4. Determine the errors in the code below and write the replacement code. #include <iostream.h> using namespace std class CRectangle { int x, y; public: void set values (int,int); int area {return (x*y);} }; void CRectangle::set_values (int a, int b) {

x = a, y = b; } int main () { Rectangle rect, rectb; Rect set_values (3,4); Rectb set_values (5,6); cout << "rect area: " << rect.area() << endl; cout << "rectb area: " << rectb.area() << endl; return () 5. Write the definition of a class named "computer" which includes the attribute "name" (the name of the computer) and a print method that prints out this name. It should also include the definition of a class named "Macintosh" that is derived from the class "computer" (computer is the base class) , the attribute "color" (a string) and a method named print that prints out the computer name and color. 6. Write brief notes on the following a) Pointer definition b) Accessing pointer values c) Array definition d) Accessing array values e) String reversal f) Function template g) Class template h) I/O file manipulation i) Error handling j) Namespace k) Type casting

You might also like