Skip to main content

Identifying Objects and Creating Software Objects

Learning Objective

  1. Identifying Real world Objects
  2. Creating Software Objects using class.
  3. Implement state and behavior of software objects.

Instructional Activities

Reference Reading:

Problem Sets


Problem Set A

1. Identify 5 objects in real world
  1. List the state of these objects
  2. List the behavior of these objects
  3. 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 program
   class 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;
              }
  }
  1. 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
  2. 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.
2. Create the class called 'Math'.
  class Math{
  private:
    int ival
  public:
     int sum(int x, int y);
 };
  1. 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
  2. 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:
  1. Create an object for the class State in the main program
  2. Call read_districts() and printDistricts() from the main program
2. Create class called Interest
  1. 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();
  2. Create an object for the class Interest in the main program
  3. call member functions, read* to read principle amount, no. of years and interest rate
  4. call calcuateSimpleInterest() and calculateCompoundInterest() to display the amount+interest separately.
3. Create class for 3 Objects identified in Problem Set A 1
Create 3 classes with state and behavior identified.
Create an object for the 3 classes in the main program and test them.



Comments

Popular posts from this blog

Mini Project - Railway Reservation System

Module 1 Overview Railway Reservation System-(RRS) Project is developed to help students learn and realize capability of C programming language, and appreciate procedural approach of developing a system. RRS helps users reserve/cancel berths, search for trains, check reservation/cancellation history, etc... On the other hand it helps the railway reservation officers to prepare reservation charts, organize train schedules, etc... RRS provides two types of log-ins one is the User log-in for railway customers and the other one is Admin log-in for railway reservation officers. Project is divided into 10 modules of four hours duration each. All the modules will give exactly what to develop in the 4 hour time frame. Since most of the modules are inter-related it is important to keep track of the previous code. After submission it is allowed to make changes in the previous code to suit / integrate well to the system. Before we start the project, we need to make the followin...

Inheritance

Week 1 - M5 : Inheritance Learning Objectives At the end of this module, you will be able to Understand the implementation of inheritance in C++ Override the base class members Access overridden base class members using the scope resolution operator Understand the concept of base class initialization Introduction Inheritance The philosophy behind inheritance is to portray things as they exist in the real world. As inheritance is found in real world, it is important feature of OO programming. Inheritance has many advantages, the most important of them being the resuability of code. Once a class is defined and debugged, it can be used to create new subclasses. The reuse of existing class saves time and effort. The Class from which another class is derived is called the base class . The class which inherits the properties of the base class is called the derived class . Each instance of the derived class includes all the members of the base class. Since...