# Ch7 prog - IMarree Carney Prof Kidd Cisp 1010 20 of Nov...

• 14

This preview shows page 1 - 6 out of 14 pages.

I’Marree CarneyProf. KiddCisp 101020 of Nov 2016/*Program Description:calculate distance and time of something fallingSource Code:Ch6num5.cppProgrammer Name: I'Marree CarneyDate:10/30/16*/#include <iostream>#include <conio.h>#include <cmath>using namespace std;void fallingDistance(){int distance, time;double g = 9.8;for (time = 1; time <= 10; time++){//for loop for time 1-10secsdistance = 0.5 * (g) * (pow(time, 2));cout << time << "\t\t\t\t " << distance << endl;}}int main(){cout << "I will calculate the falling distance(in meters) of something over 1-10 second timeframe." << endl;cout << "Time(in seconds) \t\t Distance(in meters)" << endl;fallingDistance();system("pause");return 0;}I will calculate the falling distance(in meters) of something over 1-10 second timeframe.Time(in seconds) Distance(in meters)1 42 193 444 785 1226 1767 2408 3139 39610 490Press any key to continue . . .
/*Program Description:conversion from f to c using functionsSource Code:Ch6Num7.cppProgrammer Name: I'Marree CarneyDate:10/30/16*/#include <iostream>#include <conio.h>using namespace std;void Celsius(){for (int f = 0;f <= 20;f++){double conversion;conversion = (.56 * (f - 32));cout << f << " \t " << conversion << endl;}}int main(){cout << "I am creating a function that will convert Fahrenheit to Celsius" << endl;cout << "F \t C" << endl;cout << "_______________" << endl;Celsius();system("pause");return 0;}I am creating a function that will convert Fahrenheit to CelsiusF C_______________0 -17.921 -17.362 -16.83 -16.244 -15.685 -15.126 -14.567 -148 -13.449 -12.8810 -12.3211 -11.7612 -11.2
13 -10.6414 -10.0815 -9.5216 -8.9617 -8.418 -7.8419 -7.2820 -6.72Press any key to continue . . ./*Program Description:heads or tails at randomSource Code:Ch6num8.cppProgrammer Name: I'Marree CarneyDate:10/30/16*/#include <iostream>#include <conio.h>#include <ctime>#include <cstdlib>using namespace std;int main(){int howMany = 0;int randnumber = 0;string headsTails = "";bool cointoss();cout << "How many times did you flip the coin? ";cin >> howMany;cout << howMany << endl;srand((time(0))); //seed a rand numfor (int f = 1; f <= howMany; f++){if (cointoss())headsTails = "heads";elseheadsTails = "tails";}system("pause");return 0;}bool cointoss()
{int randnumber = rand() % 2;if (randnumber == 0)return true;elsereturn false;}How many times did you flip the coin? 1010Press any key to continue . . ./*Program Description:gradebook, enter scores, drop the lowest, avg itSource Code:Ch6num11.cppProgrammer Name: I'Marree CarneyDate:10/30/16*/#include <iostream>#include <conio.h>#include <cmath>#include <cstdlib>using namespace std;void getscore(int& score){for(score = 1;score <= 5;score++)cout << "What score did you make? " << endl;cin >> score;if (score <0 || score >100){cout << "Invalid score please enter a score of 0-100." << endl;cin >> score;}else{&score;}}void calcAvg(int score1, int score2, int score3, int score4, int lowest, double& avg){avg = (score1 + score2 + score3 + score4 - lowest) / 5;}void findLowest(int score1, int score2, int score3, int score4, int score5){int lowest;lowest = score1;if (score2 < lowest)
lowest = score2;else if (score3<lowest)lowest = score3;else if (score4<lowest)lowest = score4;else if (score5<lowest)lowest = score5;return findLowest();}int main(){int score1, score2, score3, score4, score5;int lowest;double avg;getscore(score1);getscore(score2);getscore(score3);getscore(score4);getscore(score5);//for ouputcout << fixed << showpoint ;//to get lowest scorefindLowest();
• • • 