Question

In: Computer Science

Code in C++. Using ONE of the following themes to create a class and demonstrate the...

Code in C++. Using ONE of the following themes to create a class and demonstrate the idea. Use this to create a solution (two ADTs and a driver program) to demonstrate the following concepts. Create a one page summary to describe where you are using each of these concepts.

Themes:(PICK ONE)

  • a house has a door
  • a semester has a holiday break
  • a cell phone has a shatterproof case
  • a chair has a cushion

Concepts to include:

  1. composition
  2. separating interface from implementation
  3. an include guard
  4. utilizing a driver program
  5. constructor with default arguments
  6. destructor
  7. utility function
  8. toString function
  9. the this Pointer
  10. a static data member
  11. default memberwise assignment
  12. constant object
  13. constant function
  14. arrow operator
  15. cascaded function calls

Solutions

Expert Solution

ANSWER :-

GIVEN THAT :-

USING THE THEME------- A HOUSE HAS A DOOR(USING C++)

Composition (HAS-A) is achieved by the use of instance variables that are references to other objects.

****For example: a house has a door.

Let we define two abstract data seperately for house and door using the classes as ADT in c++

PROGRAM :-

#include <utility> //Utility class
#include <iostream>
#ifndef HOUSE_H //let there be a header class House.h
#define HOUSE_H //Include guards avoiding double inclusion of the header file
using namespace std;
public class House { //classname
private String location; //data members
private static int doors; //static data member
public House()
{
}
public House(String location,int doors ){ //constructor with default arguments
this.location=location;
this.doors=doors;   
}
public String getLocation() { //member functions
return location;
}
public void setLocation(String location) {
this->location = location; //this pointer using arrow operator
}
public static int getNoOfDoors() const { //constant function
return doors; //cannot modify any data member of this object
}
public static void setNoOfDoors(int doors) {
this.doors = abs(doors); //abs is a utility function for absolute value
}
public ~House(){ //Default destructor that does nothing
}
  
  
}


public class Door {

//composition has-a relationship
private House house;

public Door(){ //Constructor
this.house=new House();
house.setNoofDoors(10);
}
public int getNoOfDoors() {
return house.getNoOfDoors();
}
public getA()
{
cout <<"\nA"<<endl;

return *this;
}
  
public getB()
{
cout <<"\nB"<<endl;

return *this;
}

}

//Here is a driver program for composition that uses door object and calculate the total no. of doors in a house.


public class CheckForDoors {

int main() {
Door door();
int noofdoors = door.getNoOfDoors();
cout <<noofdoors<<endl;
door.getA().getB();
}

}

OUTPUT:-

10

A

B


Related Solutions

Using ONE of the following themes to create a class and demonstrate the idea. Use this...
Using ONE of the following themes to create a class and demonstrate the idea. Use this to create a solution (two ADTs and a driver program) to demonstrate the following concepts. Create a one page summary to describe where you are using each of these concepts. Themes:(PICK ONE) a house has a door a semester has a holiday break a cell phone has a shatterproof case a chair has a cushion Concepts to include: composition separating interface from implementation an...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
In Java, using the code provided for Class Candle, create a child class that meets the...
In Java, using the code provided for Class Candle, create a child class that meets the following requirements. Also compile and run and show output ------------------------------------------------------------------------ 1. The child class will be named  ScentedCandle 2. The data field for the ScentedCandle class is:    scent 3. It will also have getter and setter methods 4. You will override the parent's setHeight( ) method to set the price of a ScentedCandle object at $3 per inch (Hint:   price = height * PER_INCH) CODE...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election hold the names of the subdivision hold the vote counts in the Brampton subdivision for each candidate hold the vote counts in the Pickering subdivision for each candidate hold the vote counts in the Markham subdivision for each candidate Use the data from the example below. Your C program should take the...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each...
Code should be Written in C Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election hold the names of the subdivision hold the vote counts in the Brampton subdivision for each candidate hold the vote counts in the Pickering subdivision for each candidate hold the vote counts in the Markham subdivision for each candidate Use the data from the example below. * Your C program should take...
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE C++ Inventory Class Create an inventory class....
PLEASE PROVIDE COMMENTS TO BE ABLE TO UNDERSTAND CODE C++ Inventory Class Create an inventory class. The class will have the following data members, const int size = 100; int no_of_products; // the total number of products in the inventory. char name_array[size][15] ; // stores name of products double array [size][2]; // In the first column quantity of the product and in the second column the price per item of the product is stored. name_array stores the name of products,...
This is using Python, it is utilizing code from a Fraction class to create a Binary...
This is using Python, it is utilizing code from a Fraction class to create a Binary Class Please leave comments so I may be able to learn from this. Instruction for Binary Class: Exercise 6.18: Design an immutable class BinaryNumber, in the style of our Fraction class. Internally, your only instance variable should be a text string that represents the binary value, of the form '1110100'. Implement a constructor that takes a string parameter that specifies the original binary value....
Using Java, define a train class and write code to demonstrate its functionality The train should...
Using Java, define a train class and write code to demonstrate its functionality The train should run between Boston and New York, stopping at different, different station along the way. Provide output to indicate the train’s current status.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT