Solution

// Programmer: Clayton Price date: 2/17/14

// File? sci_proj.cpp class: cs 53

// Purpose: This file contains the main function for the program that will

// predict the grade for Ralph's science projects.

#include <iostream>

#include <cstdlib>

using namespace std;

int main()

{

/* -------------------- DECLARATIONS ---------------- */

const float HOOVER_PITTY_SCORE = 1; //score for nothing to show

const float HOOVER_PITTY_MULTIPLIER = 3; //change of grade when crying

const float PRICE_PER_BAG_OF_CHEMS = 2;

const float WT_PER_BAG_OF_CHEMS = 1;

const float HUNGRY_N_GLUE_PROPOR = 0.25; //part of project eaten if hungry and has glue

const float STUFF_GLOWING_PROPOR = 0.25; //part of project eaten if it contains glowing stuff

const float PUKE_AMOUNT = 1; //WT of puke added if he pukes

const float GLUE_WT = 0.5; //wt of glue he reg has

const float MAX_HOOVER_SCORE = 10;

const float MIN_A = 5.0; //minimum scores for grades

const float MIN_B = 4.0;

const float MIN_C = 3.0;

const float MIN_D = 2.0;

float stuff; //input value of junk user has collected

float money; //input valu for money brought to school

float hoover_score; //score given by teacher Miss Hoover for nothing

float gain_from_purchase; //wt of stuff bought from Bart

float loss_due_to_hunger = 0;

float loss_due_to_glow = 0;

char ans;

char another;

char grade;

bool will_cry = false; //for event Ralph cries when getting bad news

bool is_hungry = false;

bool is_glowing = false;

bool has_glue = false;

short bags_purchased = 0; //number of bags of chemicals Ralph buys

/* ---------------- INPUTS AND COMPS ------------- */

cout<<"\n\n\n\t\t*******GREETINGS RALPH*************"

<<"\n\t\tThis program will estimate your grades!"<<endl<<endl;

do

{

do

{

cout<<"how much crap did you gather: ";

cin>>stuff;

} while (stuff < 0);

do

{

cout<<"how much money did you bring: ";

cin>>money;

} while (money < 0);

if (money == 0 && stuff == 0)

{ //has no stuff nor money

hoover_score = HOOVER_PITTY_SCORE;

do

{

cout<<"\tRalph, will you cry for having nothing?(y/n) ";

cin>>ans;

} while (ans != 'y' && ans != 'n');

will_cry = (ans == 'y');

if (will_cry)

hoover_score *= HOOVER_PITTY_MULTIPLIER;

}

else

{ //has some money or stuff

bags_purchased = static_cast<short>( money / PRICE_PER_BAG_OF_CHEMS);

gain_from_purchase = bags_purchased * WT_PER_BAG_OF_CHEMS;

stuff += gain_from_purchase;

cout<<"Ralph, you can buy "<<gain_from_purchase<<" lbs of stuff to add"

<<endl;

do

{

cout<<"Are you hungry?(y/n) ";

cin>>ans;

} while (ans != 'y' && ans != 'n');

is_hungry = (ans == 'y');

do

{

cout<<"Is the bag glowing?(y/n) ";

cin>>ans;

} while (ans != 'y' && ans != 'n');

is_glowing = (ans == 'y');

do

{

cout<<"Do you have glue with you?(y/n) ";

cin>>ans;

} while (ans != 'y' && ans != 'n');

has_glue = (ans == 'y');

if (is_hungry && has_glue)

{

loss_due_to_hunger = stuff * HUNGRY_N_GLUE_PROPOR;

loss_due_to_glow = stuff * STUFF_GLOWING_PROPOR;

stuff -= loss_due_to_hunger;

if (is_glowing)

{

stuff -= loss_due_to_glow;

stuff += PUKE_AMOUNT;

}

}

else

if (is_hungry)

stuff += GLUE_WT;

hoover_score = stuff; //score is wt of stuff

}

/* ----------------- BUILDING GRADE ------------------- */

if (hoover_score > MAX_HOOVER_SCORE)

{

cout<<"ERRROR.... something wrong.....exiting"<<endl<<endl;

exit(1);

}

else if (hoover_score >= MIN_A)

grade = 'A';

else if (hoover_score >= MIN_B)

grade = 'B';

else if (hoover_score >= MIN_C)

grade = 'C';

else if (hoover_score >= MIN_D)

grade = 'D';

else

grade = 'F';

cout<<"\n\nRalph, your Hoover Score is: "<<hoover_score;

cout<<"\n\tAnd, your grade for this project is "<<grade<<endl;

cout<<"............WOW, you're a genius!"<<endl;

do //prompt for another project

{

cout<<"Ralph, do you want to score another?(y/n) ";

cin>>another;

} while (another != 'y' && another != 'n');

} while (another=='y'); //defaults to no

cout<<"\n\n\n\t\tFARE THEE WELL, RALPHY........."<<endl<<endl;

return 0;

}