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
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...
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....
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();...
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code...
Using C# Windows App Form Create a simple calculator using +,-,*,/ Please show code GUI Code for calculator menus radio button input text boxes
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a string of text entered by the user. Must accept all ASCII characters. Provide an explanation for how you got frequencies of characters, how you sorted them, and how you got codes.
Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and...
Using JAVA: Create a simple numeric code class SimpleCode that takes a set of numbers and turns them into words and sentences. The code should use the 0 to represent a space between words and 00 to represent a period at the end of a sentence. The 26 letters of the alphabet should be represented in reverse order. In other words, Z is 26 and A is one. In your final product, only the first letter of a sentence should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT