Related questions
C++ help with this fixing code
.cpp file
#include<iostream>
#include<string>
#include<
#include"Food.h"
using namespace std;
class Nutrition{
private:
string name;
double Calories
double Fat
double Sugars
double Protein
double Sodium
Nutrition(string n, double c, double f, double s, double p, double S): name(n), Calories(c), Fat(f),Sugars(s), Protein(p),Sodium(S){}
food[Calories]= food[Fat]=food[Sugars]=food[Protein]=food[Sodium]=0;
name = "";
}
Nutrition(string type, double calories, double fat, double sugar,double protein, double sodium){
food[Calories]= calories; food[Fat]=fat; food[Sugars]= sugar; food[Protein]=protein; food[Sodium]=sodium; name= type;
}
void setName(string type){
name = type;
}
void setCalories(double calories){
food [Calories]= calories;
}
void setFat(double fat){
food [Fat]= fat;
}
void setSugars(double sugar){
food [Sugars]= sugar;
}
void setProtein(double protein){
food [Protein]= protein;
}
void setSodium(double sodium){
food [Sodium]= sodium;
}
string getName(){
return name;
}
double setCalories(){
return food[Calories];
}
double getFat(){
return food[Fat];
}
double getSugars(){
return food[Sugars];
}
double getProtein(){
return food [Protein];
}
double getSodium(){
return food[Sodium];
}
.h file
#ifndef FOOD_H
#define FOOD_H
Nutrition operator + (Nutrition & F){
Nutrition temp;
temp.food[Calories]= food[Calories + F.getCalories()];
temp.food[Fat] = food[Fat] + f.getFat();
temp.food[Sugars]= food[Sugars] + F.getSugars();
temp.food[Protein]= food[Protein]+ F.getProtein();
temp.food[Sodium] = food[Sodium] + F.getSodium();
return temp;
}
}
void display (Food text){
cout<< "Your total intake is"<<endl;
cout<< " Calories consumed:"<< text.getCalories()<<endl;
cout<< " Total Sugar consumed:"<< text.getSugars()<<endl;
cout<< " Protein consumed:"<< text.getProtein()<<endl;
cout<< " Sodium consumed" << text.getSodium<<endl;
cout<< " Fat consumed:" << text.getFat()<<endl;
}
vector<Nutrirtion>Nutrition Items;
Nutrition I1("Apple",1 4,5,7);
Nutrition I2(" French fries", 2, 5 ,6);
Nutrition I3("Burger",3, 50,60, 4,5);
Nutrition I4( "Pizza",4,36,43,4,4);
Nutrition I5(" Ramen", 5,22,34,5,5);
Nutrition I6("Steak", 6,23,27,10,10);
Nutrition I7(" Chicken", 7,19,17,7,7);
Nutrition I8(" Rice", 8, 16,3,2,2);
Nutrition I9(" Pork", 9,17,17,8,8);
Nutrition I10(" Carrots",10,17,1,1);
Nutrition I11("FInished");
Items.push_back(I1);
Items.push_back(I2);
Items.push_back(I3);
Items.push_back(I4);
Items.push_back(I5);
Items.push_back(I6);
Items.push_back(I7);
Items.push_back(I8);
Items.push_back(I9);
Items.push_back(I10);
Items.push_back(I11);
void excess(Nutrition text){
if (text.getCalories() > averageFood[Calories]){
cout<<" You exceeded the suggested amount"<< endl;
}
if (text.getFat() > averageFood[Fat]){
cout<<" You exceeded the suggested amount"<< endl;
}
if (text.getSugars() > averageFood[Sugars]){
cout<<" You exceeded the suggested amount"<< endl;
}
if (text.getProtein() > averageFood[Protein]){
cout<<" You exceeded the suggested amount"<< endl;
}
if (text.getSodium() > averageFood[Sodium]){
cout<<" You exceeded the suggested amount"<< endl;
}
}
int main(){
Nutrition Items[MAX];
int size;
int choice =-1;
Nutrition selected;
int selected Item = 0;
while ( choice != size +2){
for (int i = 0; i < size; i++){
cout << i + 1 << ":"<< list[i].get Nmaw()<<endl;
}
cout << size +2 << ": Finished"<< endl;
cin>> choice;
if (choice == size +1){
size= addItem(list,size);
}
else if )choice < size && choice>0){
selected= selected +Items[choice - 1];
selectedItemCount++;
}
else if (choice<1 || choice>size +2){
cout << "invalid"<<endl;
}
if ( selectedItemCount > 0){
print (selected);
cout << endl;
checkexcess(selected);
}
}
return 0;
}
create a class to contain a "Food Item". This food item class should track the name of the food, calories, total fat, total sugars, protein, and sodium. The class's member variables should only be accessible via public accessors or mutators, if necessary. It should contain no public member variables.
Override the addition operator to allow food items to be added together. The result of the addition should populate a class containing the combined nutritional value of the two items. Use this operator to sum up the nutritional value of all the food items selected by the user.
The program should display at least 10 pre-populated items for the user to choose from.
After all food entries have been entered into the console and the total nutritional value has been computed, display to the user if they have exceeded any of the recommended intakes for an average adult:
Class files are stored in separate files
Step by stepSolved in 2 steps
Where are the list of food items that were made using the
Where are the list of food items that were made using the
- Create an Organization class. Organization has 10 Employees (Hint: You will need an array of pointers to Employee class) Organization can calculate the total amount to be paid to all employees Organization can print the details(name & salary) of all employees note: write code in main,header and function.cpp filearrow_forward#include #include #include "Product.h" using namespace std; int main() { vector productList; Product currProduct; int currPrice; string currName; unsigned int i; Product resultProduct; cin>> currPrice; while (currPrice> 0) { } cin>> currPrice; main.cpp cin>> currName; currProduct.SetPriceAndName (currPrice, currName); productList.push_back(currProduct); resultProduct = productList.at (0); for (i = 0; i < productList.size(); ++i) { Type the program's output Product.h 1 CSE Scanned Product.cpp if (productList.at (i).GetPrice () < resultProduct.GetPrice ()) { resultProduct = productList.at(i); } AM cout << "$" << resultProduct.GetPrice() << " " << resultProduct. GetName() << endl; return 0; Input 10 Cheese 6 Foil 7 Socks -1 Outputarrow_forwardWrite a function getNeighbors which will accept an integer array, size of the array and an index as parameters. This function will return a new array of size 2 which stores the neighbors of the value at index in the original array. If this function would result in returning garbage values the new array should be set to values {0,0} instead of values from the array.arrow_forward
- struct gameType { string title; int numPlayers; bool online; }; gameType Awesome[50]; Write the C++ statement that sets the first [0] title of Awesome to Best.arrow_forwardCreate pseudocode for the following #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; char water[10][10] = {{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'},{'~','~','~','~','~','~','~','~','~','~'}}; void createBoard(int &numShip); void promptCoords(int& userX, int &userY); void shipGen(int shipX[] ,int shipY[], int &numShip); void testCoords(int &userX, int &userY, int shipX[], int shipY[], int &numShip, int& victory); void updateBoard();arrow_forward>> IN C PROGRAMMING LANGUAGE ONLY << COPY OF DEFAULT CODE, ADD SOLUTION INTO CODE IN C #include <stdio.h>#include <stdlib.h>#include <string.h> #include "GVDie.h" int RollSpecificNumber(GVDie die, int num, int goal) {/* Type your code here. */} int main() {GVDie die = InitGVDie(); // Create a GVDie variabledie = SetSeed(15, die); // Set the GVDie variable with seed value 15int num;int goal;int rolls; scanf("%d", &num);scanf("%d", &goal);rolls = RollSpecificNumber(die, num, goal); // Should return the number of rolls to reach total.printf("It took %d rolls to get a \"%d\" %d times.\n", rolls, num, goal); return 0;}arrow_forward
- C++ programming task. main.cc file: #include <iostream>#include <map>#include <vector> #include "plane.h" int main() { std::vector<double> weights{3.2, 4.7, 2.1, 5.5, 9.8, 7.4, 1.6, 9.3}; std::cout << "Printing out all the weights: " << std::endl; // ======= YOUR CODE HERE ======== // 1. Using an iterator, print out all the elements in // the weights vector on one line, separated by spaces. // Hint: see the README for the for loop syntax using // an iterator, .begin(), and .end() // ========================== std::cout << std::endl; std::map<std::string, std::string> abbrevs{{"AL", "Alabama"}, {"CA", "California"}, {"GA", "Georgia"}, {"TX", "Texas"}}; std::map<std::string, double> populations{ {"CA", 39.2}, {"GA", 10.8}, {"AL", 5.1}, {"TX", 29.5}}; std::cout <<...arrow_forward3. int count(10); while(count>= 0) { count -= 2; std::cout << count << endl;arrow_forwardC# application that will allow users to enter values store all the expenses on that month in an array clothes, food, cool drinks, water, meatarrow_forward
- C++ This program does not compile! Spot the error and give the line number. Presume that the header file is error free and // Implementation file for the Rectangle class.1. #include "Rectangle.h" // Needed for the Rectangle class2. #include <iostream> // Needed for cout3. #include <cstdlib> // Needed for the exit function4. using namespace std; //***********************************************************// setWidth sets the value of the member variable width. *//*********************************************************** 5. void Rectangle::setWidth(double w){6. if (w >= 0)7. width = w;8. else{9. cout << "Invalid width\n";10. exit(EXIT_FAILURE);}} //***********************************************************// setLength sets the value of the member variable length. *//*********************************************************** 11. void Rectangle::setLength(double len){12. if (len >= 0)13. length = len;14. else{15. cout << "Invalid length\n";16....arrow_forwardIn C++ struct myGrades { string class; char grade; }; Declare myGrades as an array that can hold 5 sets of data and then set a class string in each position as follows: "Math" "Computers" "Science" "English" "History" and give each class a letter gradearrow_forwardC PROGRAMMING HELP I need help with an old script of mine. I'm having trouble getting math involving accessing an array to work properly, I'm getting an error message that's puzzling me. I'm pretty sure the solution is simple and right in front of me but it's stumping me. Below is the script: #include <stdio.h>#include <math.h>void value(float x){ printf("what is the value of x?"); scanf("%f",&x); }void power(float i,int p,int x,float arr[100]){ float equation,butt; printf("what is the highest power in the series?"); scanf("%d",&p); for (i = 0; i < p; ++i) equation = pow(x,i); //how the hell do i get the counter to do what i want butt = 1+equation^arr[i];}void shortcut(int x){ shortcut = 1/(1-x)}int main(){ printf("Here is the result!:") printf("%d %f", p, f); printf("If we had used shortcut, value would be: %d", shortcut); int diff; diff = shortcut - butt; printf("The difference is only %0.2f!",diff);...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education