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 in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator...
Please use original C++ code for this. This is for visual studio. Program 5: Shipping Calculator The Speedy Shipping Company will ship packages based on how much they weigh and how far they are being sent. They will only ship small packages up to 10 pounds. You have been tasked with writing a program that will help Speedy Shipping determine how much to charge per delivery. The charges are based on each 500 miles shipped. Shipping charges are not pro-rated;...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
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...
Person class You will implement the Person Class in Visual Studio. A person object may be...
Person class You will implement the Person Class in Visual Studio. A person object may be associated with multiple accounts. A person initiates activities (deposits or withdrawal) against an account that is captured in a transaction object. A short description of each class member is given below: Person Class Fields -   password : string Properties +   «C# property, setter private» IsAuthenticated : bool +   «C# property, setter absent» SIN : string +   «C# property, setter absent» Name : string Methods...
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...
Need it in C# using visual studio (also can you show me how to implement the...
Need it in C# using visual studio (also can you show me how to implement the code in vs) Create a New Project named Preferred Customer to be used in a retail store for preferred customers, where customers can earn discount on all purchases depending upon how much money they are going to spend. To begin with designing your Application, you must add a class named Person with properties for holding a Person’s Name, Address and Telephone Number. Next step...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT