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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
|
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<cstdlib>
#include<windows.h>
using namespace std;
void menu();
void tutor();
void processing();
void getRscore(char[]);
void getBscore(char[]);
void ivnmain();
void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
SetConsoleCursorPosition( hStdOut, homeCoords );
}
char EXIT='N';
int main()
{
menu();
return 0;
}
void menu ()
{
char choice;
ClearScreen();
cout<<"Welcome to the menu which contains a few of the programs I have created \n";
cout<<"during my class time. Please enter your menu choice after the menu is displayed.\n";
cout<<"Please only enter the upper or lower case letters presented as menu options,\n";
cout<<"numbers will not be accepted.\n\n";
cin>>choice;
while (choice!='a' && choice!='A' && choice!='b' && choice!='B' && choice!='c' && choice!='C' && choice!='d' && choice!='D' && choice!='e' && choice!='E')
{
cout<<"That is not a valid entry, please enter a letter that was presented as\n";
cout<<"a menu option, case does not matter." ;
cin>>choice;
cout<<endl <<endl;
}
do
{
switch(choice)
{
case 'a':
'A': tutor();
break;
case 'b':
'B': processing();
break;
case 'c':
'C': grademachine();
break;
case 'd':
'D': ivnmain();
break;
case 'e':
'E': Exit();
} break;
}
while (EXIT=='N' || EXIT=='n')
cout<<"Good bye";
system ("pause");
}
void tutor()
{
ClearScreen();
cout<<"Welcome to the Math Tutor program, run it as many times \n";
cout<<"as you need for practice!" <<endl <<endl;
unsigned seed= time (0);
srand (seed);
cout<<"You will now be presented with a math problem, please solve it.\n";
system ("pause");
cout<< endl;
double num1, num2, answer, studentanswer;
num1= rand() % 100;
num2= rand() % 100;
answer=num2-num1;
cout<<"(" << num1 <<" + y = " << num2 <<")" << endl;
cout<<"Please enter what you believe to be the correct answer: ";
cin>> studentanswer;
cout<<endl <<endl;
if (answer==studentanswer)
cout<<"You are correct!!!" <<endl;
else
cout<<"Your answer is not correct. The correct answer is: " <<answer <<endl;
}
const int SIZE=20;
void processing()
{
ClearScreen();
int numofnum, sumofnum, number;
double averagenum;
numofnum=0, sumofnum=0, averagenum=0;
ifstream numfile;
numfile.open("random.txt");
if (numfile)
{
while (numfile >> number)
{
numofnum++;
sumofnum+=number;
}
averagenum=sumofnum/numofnum;
cout<<"The number of numbers in the file is: " <<numofnum <<", the sum of all the numbers is: " <<sumofnum <<",\n";
cout<<"while the average of the numbers is: " <<averagenum <<"." <<endl;
system ("pause");
}
else
{
cout<<"There was an error reading the file, goodbye." <<endl;
}
}
void grademachine()
{
ClearScreen();
char studentanswers[SIZE];
char correctanswers[SIZE];
char wrong[SIZE];
int qnumber[SIZE];
int numberWrong = 0;
int f=0;
int average=0;
getRscore(studentanswers);
getBscore(correctanswers);
for (int index = 0; index < SIZE; index++)
{
if (studentanswers[index] != correctanswers[index])
{
wrong[numberWrong] = studentanswers[index];
numberWrong++;
qnumber[f]=index;
f++;
}
}
cout<<"The student answers have been pulled from their file and compared to \n";
cout<<"the correct answers. The amount of answers that were wrong is: " <<numberWrong<<endl;
cout<<"The incorrect answers are as follows: ";
for(int i = 0; i < numberWrong; i++)
{
cout<<qnumber[i]+1 <<"." << wrong[i] << " ";
}
int numright=SIZE-numberWrong;
average=numright/SIZE;
cout<<setprecision(2) <<fixed;
cout<<"The average is: " <<average;
cout << endl;
}
void getRscore(char score[])
{ ifstream inFile;
int count = 0;
inFile.open("StudentsAnswers.txt");
if (inFile.fail())
{
cout << "File failed to open " << endl;
cin.ignore();
exit(0);
}
inFile >> score[count];
while(inFile)
{
count++;
inFile >> score[count];
}
inFile.close();
}
void getBscore(char score[])
{ifstream inFile;
int count = 0;
inFile.open("CorrectAnswers.txt");
if (inFile.fail())
{
cout << "File failed to open " << endl;
cin.ignore();
exit(0);
}
inFile >> score[count];
while(inFile)
{
count++;
inFile >> score[count];
}
inFile.close();
}
class Inventory
{
private:
int itemNumber;
int quantity;
double cost;
double totalcost;
public:
Inventory();
Inventory(int, int, double);
void setItemnumber(int);
void setQuantity(int);
void setCost(double);
void setTotalCost(int, double);
int getItemNumber() const;
int getQuantity() const;
double getCost() const;
double getTotalCost() const;
};
Inventory::Inventory()
{
itemNumber=0;
quantity=0;
cost=0;
totalcost=0;
}
Inventory::Inventory(int number, int amount, double Cost)
{
itemNumber=number;
quantity=amount;
cost=Cost;
setTotalCost(quantity, cost);
}
void Inventory::setItemnumber(int number)
{
itemNumber=number;
}
void Inventory::setQuantity(int amount)
{
quantity=amount;
}
void Inventory::setCost(double Cost)
{
cost=Cost;
}
void Inventory::setTotalCost(int amount, double Cost)
{
totalcost=amount*Cost;
}
int Inventory::getItemNumber() const
{
return itemNumber;
}
int Inventory::getQuantity() const
{
return quantity;
}
double Inventory::getCost() const
{
return cost;
}
double Inventory::getTotalCost() const
{
return totalcost;
}
void ivnmain()
{
ClearScreen();
int ITEMNUMBER, QUANTITY;
double COST;
cout<<"Welcome, when asked to enter informations please do not enter" <<endl;
cout<<"a negative number. Please enter the first items number: ";
cin>>ITEMNUMBER;
cout<<"Please enter the first items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the first items cost: ";
cin>>COST;
Inventory item1;
item1.setItemnumber(ITEMNUMBER);
item1.setQuantity(QUANTITY);
item1.setCost(COST);
item1.setTotalCost(QUANTITY, COST);
cout<<"Thankyou, now for the second item: " <<endl;
cout<<"Please enter the second items number:";
cin>>ITEMNUMBER;
cout<<"Please enter the second items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the second items cost: ";
cin>>COST;
Inventory item2(ITEMNUMBER, QUANTITY, COST);
cout<< setprecision(2) <<fixed <<endl <<endl;
cout<<"Here are the two items you have put into inventory:" <<endl;
cout<<"Item numbered " <<item1.getItemNumber() <<" has " <<item1.getQuantity();
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item1.getCost() <<". In total they are worth $" <<item1.getTotalCost();
cout<<"." <<endl <<endl;
cout<<"Item numbered " <<item2.getItemNumber() <<" has " <<item2.getQuantity();
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item2.getCost() <<". In total they are worth $" <<item2.getTotalCost() <<endl;
system ("pause");
}
void Exit()
{
ClearScreen();
cout<<"Are you sure you want to exit? Y/N ";
cin>>EXIT;
}
|