#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:
The left table shows the vector foods (provided). The right table is the contents of array drinks after loaded from the data in foods. Items (bold) are default drinks because foods were not Liquid and Cold.
vector: foods |
||||
name |
calories |
price |
form |
temp |
beans |
8 |
.18 |
Solid |
Room |
coke |
240 |
.57 |
Liquid |
Cold |
oats |
10 |
.12 |
Solid |
Room |
steak |
310 |
12.34 |
Solid |
Frozen |
milk |
80 |
1.21 |
Liquid |
Cold |
soup |
95 |
2.34 |
Liquid |
Hot |
array: drinks |
|
name |
calories |
water |
0 |
coke |
240 |
water |
0 |
water |
0 |
milk |
80 |
water |
0 |
Part 2. [20 points] For this part you will use pointers and dynamic memory allocation.
Part 2 steps:
Part 3. [15 points] For this part you will overload operators. Provided is a class Fraction. You will add some new overloaded operator methods to class Fraction.
Part 3 steps:
Part 4. [20 points] For each step,
write a recursive version of a provided iterative
function. Provided is a recursive function body and a testing loop.
Each recursive function should only call itself (not some
other function). Avoid global and static local
variables.
Part 4 steps:
Part 5. [5 points] Extra credit, up to 5 points. Write 5 different examples of C++ code that leads to “undefined behavior” and could crash a program. Each example must have a different fault. In a comment, explain the problem. An infinite loop is a hang, not a crash.
Example of crash:
// float sum=123.45; int count=0; float
avg=dbl/count; // divide by zero, undefined behavior
You cannot use divide by zero as one of your crash behaviors, because it was provided
Here is the answer for your question in C++ Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : According to the HOMEWORKLIB POLICY, experts are allowed to answer a max of one question, when given multiple questions in a given question. Answered as per the HOMEWORKLIB POLICY. Apologies for this.
I have answered Part - 1 (Steps A - F)
(I displayed vector data in the code, it is optional only as it is asked to display only drinks array in step F, So if you don't want the data to be displayed kindly comment the lines (66 to 73) from screenshots below)
CODE :
#include <iostream> enum form_t { Solid = 'S', Liquid = 'L', Gas =
'G'}; /*In
the constructor, validate the inputs – int main(){ //(E)Create an array called drinks and load
drinks with instances constructed from food from the vector
foods. |
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
OUTPUT :
Any doubts regarding this can be explained with pleasure :)
#include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part,...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
#include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; struct menuItemType { string menuItem; double menuPrice; }; void getData(menuItemType menuList[]); void showMenu(menuItemType menuList[], int x); void printCheck(menuItemType menuList[], int menuOrder[], int x); int main() { const int menuItems = 8; menuItemType menuList[menuItems]; int menuOrder[menuItems] = {0}; int orderChoice = 0; bool ordering = true; int count = 0; getData(menuList); showMenu(menuList, menuItems); while(ordering) { cout << "Enter the number for the item you would\n" << "like to order, or...
This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...
I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink { string name; double cost; int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() { const int size = 5; Drink drinks[size] = { {"Cola", 0.65, 2}, {"Root Beer", 0.70, 1}, {"Grape Soda", 0.75, 5}, {"Lemon-Lime", 0.85, 20}, {"Water", 0.90, 20} }; cout <<...
Please complete Part 1. The code is also below:
#include <pthread.h>
#include <iostream>
using namespace std;
void *PrintHello(void *arg)
{
int actual_arg = *((int*) arg);
cout << "Hello World from thread with arg: " <<
actual_arg << "!\n";
return 0;
}
int main()
{
pthread_t id;
int rc;
cout << "In main: creating thread \n";
int t = 23;
rc = pthread_create(&id, NULL, PrintHello, (void*) &t);
if (rc){
cout << "ERROR; return code from pthread_create() is "
<< rc <<...
Use this code to create multiple functions.
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
cout << fixed << showpoint <<
setprecision(2);
ofstream outFile;
outFile.open("Feras's.txt");
outFile << "..Skinny Feras's Restaurant ..\n\n" <<
endl;
int choise=10, quantity;
float paid, SubTotal=0, Tax = .10, Total, RM, more;
while(choise!=0)
{
system("cls");
cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**"
<< endl;
cout << "\nWhat would you like to have?" <<
endl;
cout << "1. Burger." << endl;
cout << "2. Pizza." <<...
Given the following code: #include <iostream> #include <iomanip> using namespace std; class Animal{ private: int height; int weight; public: void setHeight(int h){ height = h; } int getHeight(){ return height; } void setWeight(int w){ weight = w; } int getWeight(){ return weight; } virtual void makeSound() = 0; virtual void eat(); }; class Dog: public Animal{ public: void makeSound(){ cout << "Bow Bow\n"; } void eat (){ cout <<"The dog is eating\n"; } void Catch(){ cout << "The dog is...
#include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...