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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
//Library Section
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <ExtraLibrary.h>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <apmatrix.h>
using namespace std;
//struct section
struct Planet
{ //All measurements are in kilometers!
string Name;
double Distance;
double PoR;
double Rotation;
long Diameter;
int SN;
int Rings;
};
//global var section
char Ans;
int I;
vector<Planet>Planets(9);
int Choose;
ifstream in_file;
ofstream out_file;
//prototype section
void display(int&);
void ask(int&);
void Planetdata(vector<Planet>&, ofstream&);
void main()
{
do{
system("cls");
Planetdata(Planets, I);
ask(Choose);
system("cls");
display(Choose);
cout<<"Run program again? (Y/N)"<<endl;
cin>>Ans;
}while(Ans=='y'||Ans=='Y');
}
void Planetdata(vector<Planet>&Planets, int&I)
{
for(I=0;I<9;I++)
in_file>>Planets[I];
}
void ask(int&Choose, ifstream&in_file)
{
do{
cout <<"Please select a number - enter the number leading to the corresponding planet:"<<endl<<endl;
cout <<"1 - Mercury"<<endl;
cout <<"2 - Venus"<<endl;
cout <<"3 - Earth"<<endl;
cout <<"4 - Mars"<<endl;
cout <<"5 - Jupiter"<<endl;
cout <<"6 - Saturn"<<endl;
cout <<"7 - Uranus"<<endl;
cout <<"8 - Neptune"<<endl;
cout <<"9 - Pluto"<<endl;
cin>>Choose;
if(Choose<1||Choose>9)
cout<<"Not a valid planet choice, please try again. Press any key to try again.";
getch();
system("cls");
}while(Choose<1||Choose>9);
Choose--;
}
void display(int&Choose)
{
cout<<"Planet Name:"<<endl;
gotoxy(54,0);
cout<<Planets[Choose].Name;
gotoxy(0,1);
cout<<"Distance from the Sun (in millions of kilometers):"<< endl;
gotoxy(54,1);
cout<<Planets[Choose].Distance;
gotoxy(0,2);
cout<<"Revolution (in Earth years): "<<endl;
gotoxy(54,2);
cout<<Planets[Choose].PoR;
gotoxy(0,3);
cout<<"Rotation (in Earth days): "<<endl;
gotoxy(54,3);
cout<<Planets[Choose].Rotation;
gotoxy(0,4);
cout<<"Equatorial Diameter (kilometers): "<<endl;
gotoxy(54,4);
cout<<Planets[Choose].Diameter;
gotoxy(0,5);
cout<<"Satellites: "<<endl;
gotoxy(54,5);
cout<<Planets[Choose].SN;
gotoxy(0,6);
cout<<"Rings: "<<endl;
gotoxy(54,6);
cout<<Planets[Choose].Rings;
}
| |