INPUT FILE FOR PROJECT
Sinclair Community College
0.50 6
0.75 5
0.50 9
0.75 4
1.00 3
Wright State University
0.90 4
1.00 6
0.90 3
1.00 2
1.25 4
University of Dayton
1.00 3
1.25 5
1.00 2
1.25 6
2.00 4
The Ohio State University
0.80 5
0.90 4
0.80 7
0905 3
1.50 2
Clark State Community College
0.75 1
0.85 2
0.75 4
0.85 2
1.00 5
Ohio University
1.00 2
1.25 6
1.00 7
1.25 3
1.50 2
C++ code:
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int n;
enum SodaBrands {COKE,DIET_COKE,SPRITE,SPRITE_ZERO,DASAN};
struct Drinks
{
double price;
int numSodas;
};
const int MAX_SODA_BRANDS = 5;
struct vendingMachine
{
string location;
Drinks sodas[MAX_SODA_BRANDS];
};
SodaBrands convertDrink(string s)
{
if(s=="Coke") return COKE;
else if(s=="Diet Coke") return DIET_COKE;
else if(s=="Sprite") return SPRITE;
else if(s=="Sprite Zero") return SPRITE_ZERO;
else if(s=="Dasani Water") return DASAN;
}
void getDrinkName(SodaBrands sb, string& str)
{
if(sb==COKE) str = "Coke";
else if(sb==DIET_COKE) str = "Diet Coke";
else if(sb==SPRITE) str = "Sprite";
else if(sb==SPRITE_ZERO) str = "Sprite Zero";
else if(sb==DASAN) str = "Dasani Water";
}
int getLocation(vendingMachine vM[])
{
cout<<"Select your location from the following : "<<endl;
for(int i=0;i<n;i++)
{
cout<<i<<": "<<vM[i].location<<endl;
}
cout<<n<<": Exit"<<endl;
int t;
cout<<endl<<"Your Location: ";
cin>>t;
while(t<0 || t>n)
{
cout<<"Invalid input!! Enter your location again: ";
cin>>t;
}
return t;
}
int getDrinkSelection()
{
cout<<"Soda choices: "<<endl<<endl;
for(int s=0; s<5; s = s+1)
{
string str ;
getDrinkName(SodaBrands(s),str);
cout<<s<<": "<<str<<endl;
}
int t;
cout<<endl<<"Enter Soda Choice: ";
cin>>t;
while(t<0 || t>4)
{
cout<<"Invalid input!! Enter your soda choice again : ";
cin>>t;
}
return t;
}
void makePurchase(vendingMachine vM[],int x,int y)
{
cout<<"You selected location: "<<vM[x].location<<endl;
string str ;
getDrinkName(SodaBrands(y),str);
cout<<"Drink Selection: "<<str<<endl;
double amt;
cout<<"Please enter amount paid $";
cin>>amt;
cout<<"Change due: $";
printf("%.2f\n", amt - vM[x].sodas[y].price);
if(vM[x].sodas[y].numSodas>0 )vM[x].sodas[y].numSodas-=1;
}
void showVendingMachines(vendingMachine vM[])
{
for(int k=0;k<n;k++)
{
cout<<"Machine location: "<<vM[k].location<<endl;
for(int j = 0;j<5;j++)
{
string str ;
getDrinkName(SodaBrands(j),str);
cout<<"\t"<<str<<" Price - "<<vM[k].sodas[j].price<<" # sodas: "<<vM[k].sodas[j].numSodas<<endl;
}
cout<<endl;
}
}
void loadVendingMachines(vendingMachine vM[])
{
string file = "vendingMachines.txt";
ifstream fobj;
fobj.open(file);
if(!fobj.good())
{
cout<<"Problem in opening file!!"<<endl;
}
else
{
int i = 0 ;
while(fobj.good())
{
getline(fobj,vM[i].location);
fobj>>vM[i].sodas[COKE].price;
fobj>>vM[i].sodas[COKE].numSodas;
fobj>>vM[i].sodas[DIET_COKE].price;
fobj>>vM[i].sodas[DIET_COKE].numSodas;
fobj>>vM[i].sodas[SPRITE].price;
fobj>>vM[i].sodas[SPRITE].numSodas;
fobj>>vM[i].sodas[SPRITE_ZERO].price;
fobj>>vM[i].sodas[SPRITE_ZERO].numSodas;
fobj>>vM[i].sodas[DASAN].price;
fobj>>vM[i].sodas[DASAN].numSodas;
string str;
getline(fobj,str);
i++;
}
n = i;
}
}
int main()
{
vendingMachine vM[10];
loadVendingMachines(vM);
while(1)
{
int t = getLocation(vM);
if(t==n) {
showVendingMachines(vM);
exit(0);
}
int s = getDrinkSelection();
makePurchase(vM,t,s);
cout<<endl;
}
return 0;
}
OUTPUT
INPUT FILE FOR PROJECT Sinclair Community College 0.50 6 0.75 5 0.50 9 0.75 4 1.00...
NOTE #1: NO GLOBALS, In addition programs with infinite while(true) loops or improper breaks etc. NOTE #2: MAKE YOUR PROGRAM AS EFFICIENT AS POSSIBLE. Drink Machine Simulator - Based on Structures Lecture Write a c++ program that simulates a soft drink machine. The program should use a structure named Drink that contains the following information: the drink name the drink cost the number of drinks in the machine The program should then create an array of 5 Drink structures. The...
1.00 0.75- fractional saturation 0.50 0.25- 0.00 0 T 7 1 2 3 4 5 6 [ligand] mM Above are shown ligand binding curves for protein DOT (black circles) and protein TRG (black triangles). Choose the correct option that best describes the data. TRG's Kd for ligand is 0.6 mm DOT binds to ligand with a 5 fold higher affinity than TRG DOT binds ligand less efficiently that TRG, the DOT affinity is 5-fold lower that TRG TRG and DOT...
Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...
Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...
Input (stdin) 7 N 4 5 N 9 6 N 16 3 R N 12 8 R R Expected Output 9 12 4 Make it in java Josefine is in charge of the local student organization at The University of Algorithms. The organization gets tasks they must complete. Each task has a unique id and a unique difficulty. Over time new tasks are given to the organization, and Josefine is then responsible for delegating these to the members of the...
write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and remains open until the...
Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...
#include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part, your program loads a vending machine serving cold drinks. You start with many foods, some are drinks. Your code loads a vending machine from foods, or, it uses water as a default drink. Create class Drink, make an array of drinks, load it and display it. Part 1 steps: [5 points] Create a class called Drink that contains information about a single drink. Provide...