1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
// Character Declarations
char Y; // to rerun the program
// Constaints
const int Capacity = 50;
// Function Declarations
void fillArray(string[], double[], int&);
void printArray(string[], double[], int);
int main()
{
// Output Identification
system("CLS");
cout << "In-class #11 by Christopher Adique -\n "
<< "Reverse Rocket Order\n\n";
double newMass[Capacity]; // array for mass
string newName[Capacity]; // array for names
int numOfElements = 0; // number of elements
do{
fillArray(newName,newMass,numOfElements);
printArray(newName, newMass, numOfElements);
cout << "\n\nWould you like to run the program again (Y=Yes) => ";
cin >> Y;
}
while (Y == 'Y' || Y == 'y');
cout << "\n\nEnd Program.\n";
return 0;
}
void fillArray(string newName[], double newMass[], int& numOfElements){
int i = 0; // inital value for i
double mass; // input mass
std::string name; // input name
std::string junk; // clear out name
while ((name != "END") && (i < Capacity)){
cout << "\nEnter a rocket name (END to end list): ";
std::getline (std::cin,name);
newName[i] = name;
if (name != "END"){
cout << "\nWhat is the mass of " << name << ": ";
cin >> mass;
newMass[i] = mass;
std::getline (std::cin,junk);
}
numOfElements++;
i++;
}
}
void printArray(string newName[], double newMass[], int numOfElements){
cout << "\nThe rockets entered in reverse order are: \n";
for (int i = (numOfElements - 2); i >= 0; i--) {
cout << left << setw(25) << newName[i] << setw(10) << right << newMass[i] << endl;
}
}
|