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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
/* Programmer : Alexander Nichols
Date : 9/23/2015
Project 1 : Droning on about c++
Description: Describe the assignment, and your solution to Project 1.
*/
#include <iostream> // input and output functionality
#include <fstream> //for input and output files
#include <iomanip> // formatting
#include <cmath> // math functions
using namespace std;
const string author ="Alexander Nichols";
const int KEY =11;
int main()
{
//variable declarations
int securityCode=0, fuelLevel=0, serialNum=0, num_data_pts=0;
string name="blank", flightStatus="blank", mission="blank";
double heat, humidity, toxicity, altitude, pressure,reading;
double x_drone=9.9, y_drone=9.9, z_drone=9.9, time=9.9, min=z_drone,
max=y_drone, sum=x_drone;
heat=humidity=toxicity=altitude=pressure=reading=sum=9.9;
double x_home=9, y_home=9, z_home=9, distance =9;
double x_mid=9, y_mid=9, z_mid=9;
ofstream outFile; //output file stream variable
ifstream inFile; //input file stream variable
string inputFileName; //variable to store name of input file
// Prompt for input file name, and validate the
// input file stream. If unsuccessful, display the
// required message and terminate the program gracefully.
cout <<author<<"\n";
cout <<"\nEnter input file name:";
cin >>inputFileName;
inFile.open(inputFileName.c_str());
if(!inFile){
cout<<"\nInput File Error!\n";
return 1;
}
//Validate the output file stream. If unsuccessful,
//display required message and terminate the program gracefully.
if(!outFile) {
cout<<"\nOutput File Error!\n";
return 0;
}
inFile >> securityCode;
//Determine the validity of the security code.
// (a) if valid, process the data as required
// (b) if invalid, communicate required message, and
// terminate the program properly (close the file streams)
if (securityCode % KEY == 0 )
{
outFile <<"DRONE INFORMATION & STATISTICS"
<<"\n------------------------------"
<<"\n Code:\t"
<<"\n Name:\t"
<<"\n S/N :\t"
<<"\n Stat:\t"
<<"\n Role:\t"
<<"\n Fuel:\t"
<<"\n Loc:\tx:"
<<"\n Sensors:"
<< " Data Readings"
<< "\n---------------\n";
cout<<"\nInvalid Security Code!\n";
return 0;
}
else{
// Begin reading and storing the data from the file.
//Set up formatting for output.
cout.fill(' '); //set the fill character to ' ' (space)
cout.flags( ios::showpoint | ios::fixed ); //set formatting flags
cout.precision(2);
// Begin outputting data to the screen
cout <<"DRONE INFORMATION & STATISTICS"
<<"\n------------------------------"
<<"\n Code:\t"
<<"\n Name:\t"
<<"\n S/N :\t"
<<"\n Stat:\t"
<<"\n Role:\t"
<<"\n Fuel:\t"
<<"\n Loc:\tx:"
<<"\n Sensors:"
<< " Data Readings"
<< "\n---------------\n";
//set formatting flags
cout.flags( ios::showpoint | ios::fixed );
cout.precision(2);
//Process the data pairs, outputting the paired data values and
// calculating the required statistics.
// process pair (a,b)
// read the first pair of sensor data
//store 1st value for future compares
//while we haven't reached end-of-file
//start adding up our data readings
//is it bigger than current max?
// ... if so, then store it in max
//is it smaller than current min?
// ... if so, then store it in min
//increase our count
while(!inFile.eof())
{
inFile >> time >>reading;
cout <<"\ "<<time<<"\t"<<reading<<"\n";\
sum =sum+reading;
num_data_pts++;
// read the next line of data
//end of our file reading while loop
// calculate distance from drone to home base
// calculate midpoint coordinates between drone and home base
//set formatting flags
outFile.fill(' '); //set the fill character to ' ' (space)
outFile.flags( ios::showpoint | ios::fixed ); //set formatting flags
outFile.precision(3);
// write data to output file
//output the drone and midpoint x,y,z coordinates
//format output correctly using <iomanip> functions
//output the calculated distance and data pair statistics
outFile << "\n====================================\n";
///Done!,..close the file stream variables correctly, and exit the program.
return 0;
}
}
// end of main()
//=========================================================
|