Skip to content

Instantly share code, notes, and snippets.

@StoleMlekokrad
Created April 30, 2017 10:16
Show Gist options
  • Save StoleMlekokrad/9ca13a93e0a0e22d191e50d7e63739f7 to your computer and use it in GitHub Desktop.
Save StoleMlekokrad/9ca13a93e0a0e22d191e50d7e63739f7 to your computer and use it in GitHub Desktop.
Nasa Space Apps 2017
#pragma once
#include <stdc++.h>
#include "food.h"
void main();
void examine_cpr()
{
std::ifstream read("db/cpr/capriciossa_rating_dough.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"pizza dough\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/cpr/capriciossa_rating_ham.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"ham\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/cpr/capriciossa_rating_mozzarella.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"mozzarella\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/cpr/capriciossa_rating_mushrooms.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"fresh mushrooms\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;
read.open("db/cpr/capriciossa_rating_olives.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"olives\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl << std::endl;
main();
}
void examine_mar()
{
std::ifstream read("db/mghr/margherita_rating_dough.txt");
if (read.is_open())
{
size_t rating = 0;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = "Resource extraction: ";
arr[1] = "Manufacutre: ";
arr[2] = "Useage: ";
arr[3] = "End-of-Life Management: ";
std::cout << "The ratings for the \"pizza dough\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; i < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/mghr/margherita_rating_basil.txt");
if (read.is_open())
{
size_t rating = 0;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = "Resource extraction: ";
arr[1] = "Manufacutre: ";
arr[2] = "Useage: ";
arr[3] = "End-of-Life Management: ";
std::cout << "The ratings for the \"basil\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; i < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/mghr/margherita_rating_garlic.txt");
if (read.is_open())
{
size_t rating = 0;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = "Resource extraction: ";
arr[1] = "Manufacutre: ";
arr[2] = "Useage: ";
arr[3] = "End-of-Life Management: ";
std::cout << "The ratings for the \"garlic\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; i < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;
read.open("db/mghr/margherita_rating_mozzarella.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"mozzarella\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;
read.open("db/mghr/margherita_rating_olive.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"olive oil\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;
read.open("db/mghr/margherita_rating_tomato.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"tomatoes\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;
read.open("db/mghr/margherita_rating_tomatoS.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"tomatoe sauce\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl << std::endl;
main();
}
void examine_vege()
{
std::ifstream read("db/vege/vegetarian_rating_dough.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"pizza dough\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/vege/vegetarian_rating_basil.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"basil\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/vege/capriciossa_rating_mozzarella.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"mozzarella\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;//newline
read.open("db/vege/vegetarian_rating_diced.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"diced tomato can\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl;
read.open("db/vege/vegetarian_rating_garlic.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"garlic\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl << std::endl;
read.open("db/vege/vegetarian_rating_olive.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"olive oil\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl << std::endl;
read.open("db/vege/vegetarian_rating_onion.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"onions\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
read.close();
std::cout << std::endl << std::endl;
read.open("db/vege/vegetarian_rating_zucchini.txt");
if (read.is_open())
{
size_t rating;
size_t i = 0;
size_t numarr[4];
float avg = 0;
std::string arr[4];
arr[0] = " Resource extraction: ";
arr[1] = " Manufacutre: ";
arr[2] = " Useage: ";
arr[3] = " End-of-Life Management: ";
std::cout << "The ratings for the \"zucchini\" are: \n";
while (read >> rating)
{
numarr[i] = rating;
std::cout << arr[i] << rating << std::endl;
++i;
}
for (size_t j = 0; j < 4; ++j)
avg = avg + (numarr[j] / (float)4);
std::cout << "Average rating: " << avg << std::endl;
}
else return;
std::cout << std::endl << std::endl;
main();
}
#pragma once
#include <stdc++.h>
#include "examine_food.h"
void examine_cpr();
void examine_mar();
void examine_vege();
void main();
int yesno(std::string& str)//need to fix
{
if (str == "Yes" || str == "yes")
return 1;
else if (str == "No" || str == "no")
return 0;
else
{
std::cerr << "Please enter Yes/yes or No/no.\n";
return -1;
}
return -1;
}
void capriciossa()
{
std::ifstream read("db/cpr/capriciossa.txt");
std::string str;
std::cout << "The ingredients for Capriciossa are: \n";
size_t i = 1;
while (!read.eof())
{
std::getline(read, str);
std::cout <<" "<< i << "." << str << std::endl;
++i;
}
std::cout << "Would you like to examine the ingredients?\n";
std::string answer;
while (true)
{
std::cin >> answer;
if (yesno(answer) > 0)
{
std::cout << std::endl;
examine_cpr();
}
else if (yesno(answer) == 0)
break;
else if (yesno(answer) < 0)
continue;
}
read.close();
std::cout << std::endl << std::endl;
main();
}
void margherita()
{
std::ifstream read("db/mghr/margherita.txt");
std::string str;
std::cout << "The ingredients for Margherita are: \n";
size_t i = 1;
while (!read.eof())
{
std::getline(read, str);
std::cout << " " << i << "." << str << std::endl;
++i;
}
std::cout << "Would you like to examine the ingredients?\n";
std::string answer;
while (true)
{
std::cin >> answer;
if (yesno(answer) > 0)
{
std::cout << std::endl;
examine_mar();
}
else if (yesno(answer) == 0)
break;
}
read.close();
std::cout << std::endl << std::endl;
main();
}
void vegetariana()
{
std::ifstream read("db/vege/vegetarian.txt");
std::string str;
std::cout << "The ingredients for Vegetariana are: \n";
size_t i = 1;
while (!read.eof())
{
std::getline(read, str);
std::cout << " " << i << "." << str << std::endl;
++i;
}
std::cout << "Would you like to examine the ingredients?\n";
std::string answer;
while (true)
{
std::cin >> answer;
if (yesno(answer) > 0)
{
std::cout << std::endl;
examine_vege();
}
else if (yesno(answer) == 0)
break;
}
read.close();
std::cout << std::endl << std::endl;
main();
}
#include <stdc++.h>
#include "examine_food.h"
#include "food.h"
//finished a bit
void main()
{
std::cout << "Available dishes: \n 1.Capriciossa\n 2.Margherita\n 3.Vegetariana\n";
size_t i;
std::cout << "Choose a dish: ";
while (std::cin >> i)
{
std::cout << std::endl;
switch (i)
{
case 1:
capriciossa();
break;
case 2:
margherita();
break;
case 3:
vegetariana();
break;
default:
std::cerr << "Invalid input or the other dishes are not available\n";
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment