Question

In: Computer Science

C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...

C++ PROGRAM

Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console.

#include "stdafx.h"
#include <iostream>

using namespace std;

// Product from which the concrete products will inherit from
class Coffee
{
protected:
   char _type[15];
public:
   Coffee()
   {
   }
   char *getType()
   {
       return _type;
   }
};

// One concrete class
class Espresso : public Coffee
{
public:
   Espresso() : Coffee()
   {
       strcpy_s(_type, "Espresso");
       cout << endl << "Making a cup of espresso" << endl;
       cout << "Grind and brew one scoop of espresso beans." << endl;
   }
};

// Another concrete class
class Cappuccino : public Coffee
{
public:
   Cappuccino() : Coffee()
   {
       strcpy_s(_type, "Cappuccino");
       cout << endl << "Making a cup of cappuccino" << endl;
       cout << "Grind and brew one scoop of espresso beans." << endl;
       cout << "Heat and foam milk." << endl;
   }
};

class CoffeeMakerFactory
{
private:
   Coffee * _coffee;
public:
   Coffee * GetCoffee()
   {
       int choice;

       cout << "Select type of coffee to make: " << endl;
       cout << "1: Espresso" << endl;
       cout << "2: Cappuccino" << endl;
       cout << "Selection: " << endl;
       cin >> choice;

       switch (choice)
       {
       case 1:
           return new Espresso;
       case 2:
           return new Cappuccino;
       default:
           cout << "Invalid Selection" << endl;
           return NULL;
       }
   }
};

int main()
{

}

Solutions

Expert Solution

Note :- I have added the driver program in main. Which calls the required functions in order to match your requirement

C++ program :-


#include <iostream>
#include <string.h>

using namespace std;

// Product from which the concrete products will inherit from
class Coffee
{
protected:
char _type[15];
public:
Coffee()
{
}
char *getType()
{
return _type;
}
};

// One concrete class
class Espresso : public Coffee
{
public:
Espresso() : Coffee()
{
strcpy(_type, "Espresso");
cout << endl << "Making a cup of espresso" << endl;
cout << "Grind and brew one scoop of espresso beans." << endl;
}
};

// Another concrete class
class Cappuccino : public Coffee
{
public:
Cappuccino() : Coffee()
{
strcpy(_type, "Cappuccino");
cout << endl << "Making a cup of cappuccino" << endl;
cout << "Grind and brew one scoop of espresso beans." << endl;
cout << "Heat and foam milk." << endl;
}
};

class CoffeeMakerFactory
{
private:
Coffee * _coffee;
public:
Coffee * GetCoffee()
{
int choice;

cout << "Select type of coffee to make: " << endl;
cout << "1: Espresso" << endl;
cout << "2: Cappuccino" << endl;
cout << "Selection: " << endl;
cin >> choice;

switch (choice)
{
case 1:
return new Espresso;
case 2:
return new Cappuccino;
default:
cout << "Invalid Selection" << endl;
return NULL;
}
}
};

int main()
{
CoffeeMakerFactory drv_obj;
Coffee *cof_obj;
  
cof_obj = drv_obj.GetCoffee();
cout<<endl<< "The selected object is of type : "<<cof_obj->getType();

return 0;   

}


Related Solutions

answer the following using C# Design and program a Visual Studio Console project in C# that...
answer the following using C# Design and program a Visual Studio Console project in C# that allows your user to enter a number. The program will examine the number to see if it is prime. If it is prime, it will print the next higher prime and the next lower primes to the console. If the number entered by the user is not prime, display a message to that effect. All code should be written by you. Do not copy/paste...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header containing your name and a brief description of the program Output prompting the user for the following inputs: Name as a string Length of a rectangle as a double Width of a rectangle as a double Length of a square as an int After accepting user input, the program outputs the following: User name Area of a rectangle with dimensions matching the inputs Area...
using Visual Studio write a code containing a main() program that implements the coin change state...
using Visual Studio write a code containing a main() program that implements the coin change state machine in C++ according to the guidance given in Translating a state machine to C++ Test your code using prices 1 and 91 cents, and assume change is calculated from a dollar bill. Copy and paste your console output to a text editor and save the result in a single file named console.txt. Upload your exercise081.cpp and console.txt files to Canvas.
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Write a C program The Visual Studio project itself must make its output to the Console...
Write a C program The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 3%: Looping Menu with 3 main actions: View Cars, Sell Car, View Sales Note: A Car is defined by its price and model 3%: Must contain at least three arrays to record sales figures (maximum of 10 Car models) Two for recording the price and model of one...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file...
use VISUAL STUDIO CODE to write this javascript program Exercise 1 (a) Create a HTML file that uses createElement and appendChild to dynamically insert three paragraphs when a button is clicked. (b) Create a HTML file that includes JavaScript that is similar to: let recs = [“my item …1”,”my item…2”, …] i.e. an array that contains several CSV item records. When the user clicks a button, each array element will be rendered as a list element. Use a HTML list....
Write a C program of car sale: The Visual Studio project itself must make its output...
Write a C program of car sale: The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum: 10%: Looping Menu with 2 main actions: Sell Car, View Sales Note: A Car is defined only by its price 10% Must contain at least one array containing sales figures (each entry represents the price of one vehicle) for a maximum of 10 Cars 5%:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT