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

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...
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%:...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
Download the attached file/s, copy and paste the code segment/s into your visual studio or any...
Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have to implement a small intentional bug in your program // This program uses a function that returns a value. #include <iostream> using namespace std; // Function prototype int sum(int num1, int num2); int main() {    int value1 = 20,   // The first value        value2 = 40,   // The second value        total;         //...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout,...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout, \n, \t, solving expressions )  Correcting errors Q1: Draw flow Chart of the following problems: a) Display “Hello World” on screen. b) Display Your Name, date of birth and mobile number on screen. c) Compute and display the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches. d) Compute and display the perimeter and area...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT