Learning Objective
- Identifying Real world Objects
- Creating Software Objects using class.
- Implement state and behavior of software objects.
Instructional Activities
Reference Reading:Problem Sets
Problem Set A
1. Identify 5 objects in real world- List the state of these objects
- List the behavior of these objects
- Note: Your list of objects should be unique from the entire class. Otherwise you would be give zero marks for the whole of this module
Problem Set B
1. Classes and Objects: Using the following class create an object for it in the main programclass Integer { private: int integer; public: void readInteger(); void printMessage(); }; void Integer::readInteger() { cout<<"enter the value of N"; cin>>N; } void Integer::printMessage() { for (int i = 0 ; i < N ; i++) { cout<<Hello<<endl; } }
- Create a object called “intobj” for the class “Integer” in the main program
- Call intobj.readInteger() and intobj.printMessage() from the main program
- Add another member function called int addInteger(int no) to the class Integer.
- The function addInteger() returns the sum of the value of “N + no”.
- Call intobj.addInteger() from the main program
- Create a class called "class Circle { };"
- Add members function to readRadius
- Add a member function to displayArea
- Create an object for the class Circle
- Call the member functions readRadius() and displayArea() from the main program.
class Math{ private: int ival public: int sum(int x, int y); };
- Create a class called “Math”
- Complete the member function int sum(int x, int y);
- return the sum of x and y;
- Write a main program which creates an object say “m” for the class “Math”
- From the main program read two integers i1, i2.
- Call the member function “total = m.sum(i1, i2)” to get the sum of i1 + i2
- Complete the member function int sum(int x, int y);
- Accessing private member in member functions:
- Modify the member functions so that sum() stores the output in ival.
- ival = x + y; return ival;
Problem Set C
1. Create a class called State() with the following member functions- readDistricts(); //read N = no of districts, dynamically allocated memory for N strings, read each district name from the stdin.
- printDistricts(); //print the district names on the standard output (display-screen);
- Use dynamic allocation of strings in the classes is compulsory:
- Create an object for the class State in the main program
- Call read_districts() and printDistricts() from the main program
- Create class called Interest with the following attributes and behavior
- Attributes
- Principle Amount
- Number of Years
- Rate of Interest
- Behavior
- readPrincipleAmount();
- readNoOfYears();
- readInterestRatePY();
- calcuateSimpleInterest();
- calculateCompoundInterest();
- Attributes
- Create an object for the class Interest in the main program
- call member functions, read* to read principle amount, no. of years and interest rate
- call calcuateSimpleInterest() and calculateCompoundInterest() to display the amount+interest separately.
Create 3 classes with state and behavior identified.
Create an object for the 3 classes in the main program and test them.
Comments
Post a Comment