first semester files
This commit is contained in:
60
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-1ASharpe.cpp
Executable file
60
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-1ASharpe.cpp
Executable file
@@ -0,0 +1,60 @@
|
||||
/***************************************************************
|
||||
* Name: Aidan Sharpe
|
||||
* Course: Computer Science & Programming
|
||||
* Class: CS04103 Section: 6
|
||||
* Assignment Date: 10.13.2021
|
||||
* File Name: Lab05-1ASharpe.cpp
|
||||
*****************************************************************
|
||||
* ID: Lab 5 Problem 1
|
||||
* Purpose: Calculate the average miles per gallon of 3 planes over a 1000 mile flight
|
||||
*****************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
float calcMPG(float miles, float gallons);
|
||||
|
||||
int main()
|
||||
{
|
||||
string make, model, mostEfficientPlane;
|
||||
float gallonsUsed, milesPerGallon, mostEfficientMPG = -1;
|
||||
const float FLIGHT_DISTANCE = 1000;
|
||||
const int PLANES = 3;
|
||||
|
||||
for(int i = 0; i < PLANES; i++)
|
||||
{
|
||||
cout << endl << "Enter the make and model of plane #" << i+1 << ": ";
|
||||
cin >> make;
|
||||
cin >> model;
|
||||
do
|
||||
{
|
||||
cout << "Enter the number of gallons used during the 1000mi flight: ";
|
||||
cin >> gallonsUsed;
|
||||
} while (gallonsUsed <= 0); // make sure that the user enters a valid number of gallons consumed
|
||||
|
||||
// calculate the miles per gallon
|
||||
milesPerGallon = calcMPG(FLIGHT_DISTANCE, gallonsUsed);
|
||||
|
||||
// determine if the current plane is the most efficient one so far
|
||||
if (mostEfficientMPG == -1 || milesPerGallon > mostEfficientMPG)
|
||||
{
|
||||
mostEfficientMPG = milesPerGallon;
|
||||
mostEfficientPlane = make + ' ' + model;
|
||||
}
|
||||
|
||||
// display the MPG for the current plane
|
||||
cout << "The average MPG of the " << make << ' ' << model << " is " << milesPerGallon << '.' << endl;
|
||||
}
|
||||
|
||||
// display the most fuel efficient plane
|
||||
cout << endl << "The most efficient plane was the " << mostEfficientPlane << " with an MPG of " << mostEfficientMPG << '.';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// function to calculate miles per gallon
|
||||
float calcMPG(float miles, float gallons)
|
||||
{
|
||||
return miles/gallons;
|
||||
}
|
||||
BIN
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-1ASharpe.exe
Executable file
BIN
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-1ASharpe.exe
Executable file
Binary file not shown.
44
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-2ASharpe.cpp
Executable file
44
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-2ASharpe.cpp
Executable file
@@ -0,0 +1,44 @@
|
||||
/***************************************************************
|
||||
* Name: Aidan Sharpe
|
||||
* Course: Computer Science & Programming
|
||||
* Class: CS04103 Section: 6
|
||||
* Assignment Date: 10.13.2021
|
||||
* File Name: Lab05-2ASharpe.cpp
|
||||
*****************************************************************
|
||||
* ID: Lab 5 Problem 2
|
||||
* Purpose: Calculate the profit made from stocks
|
||||
*****************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
float profit(float NS, float SP, float SC, float PP, float PC);
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
float NS, SP, SC, PP, PC;
|
||||
|
||||
// get investment information
|
||||
cout << "Number of shares: ";
|
||||
cin >> NS;
|
||||
cout << "Sale price per share: ";
|
||||
cin >> SP;
|
||||
cout << "Sale commission paid: ";
|
||||
cin >> SC;
|
||||
cout << "Purchase price per share: ";
|
||||
cin >> PP;
|
||||
cout << "Purchase commission paid: ";
|
||||
cin >> PC;
|
||||
|
||||
// display profit or loss
|
||||
cout << endl << "The profit on the investment was $" << profit(NS, SP, SC, PP, PC);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// calculate the profit of an investment
|
||||
float profit(float NS, float SP, float SC, float PP, float PC)
|
||||
{
|
||||
return ((NS * SP) - SC) - ((NS * PP) + PC);
|
||||
}
|
||||
BIN
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-2ASharpe.exe
Executable file
BIN
1st-Semester-Fall-2021/CSNP/CSNP-04103-Lab-#5/Lab05-2ASharpe.exe
Executable file
Binary file not shown.
Reference in New Issue
Block a user