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...
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.
Please analyze and create a starter code in Python using spaCy, that can demonstrate practical use...
Please analyze and create a starter code in Python using spaCy, that can demonstrate practical use of the package. Also give a brief explanation of what the purpose of the spaCy package is. Please use 3 different methods such as a loop statement, if statement, tuples, lists etc. Please provide detailed comments on each line of code. Please explain the purpose of the method used. Please write and run your code example.
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT