rendered paste body/************************************************************************************* @File: main.cpp**** @Title: CPP-Learning**** @Author: Jamie Sharpe**** @Date: 18 September 2011**** @Version: 0.01**** @Description:** This file contains various** exercises.***********************************************************************************/#include <iostream>#include <fstream>#include <string>using namespace std;//Prototype functions//void ifStatement();void switchStatement();void whileStatement();void forStatement();void doWhileStatement();void fileWrite();void fileRead();void inputError();void mainOptions();int main(){ cout << "Welcome to CPP-Learning!" << endl; mainOptions(); int userInput = 0; while( cin >> userInput ) { switch ( userInput ) { case 1: ifStatement(); break; case 2: switchStatement(); break; case 3: whileStatement(); break; case 4: forStatement(); break; case 5: doWhileStatement(); break; case 6: fileWrite(); break; case 7: fileRead(); break; default: inputError(); break; } } return 0;}void ifStatement(){ cout << "if statement function selected!" << endl; int ifTest = 10; //Change this value to generate different results. cout << "Enter a number and it will be compared to the number 10" << endl; cin >> ifTest; if ( ifTest < 10 ) { cout << ifTest << " is less than 10" << endl; } else if ( ifTest == 10 ) { cout << ifTest << " is the same as 10" << endl; } else if ( ifTest > 10 ) { cout << ifTest << " is more than 10" << endl; } else { cout << "Something went wrong!" << endl; } cout << "end of function" << endl; mainOptions();}void switchStatement(){ cout << "switch statement function selected!" << endl; int switchTest = 0; cout << "Enter a number from 0 to 9" << endl; cin >> switchTest; switch ( switchTest ) { case 0: cout << "switchTest is 0" << endl; break; case 2: //intentional fallthrough case 4: //intentional fallthrough case 6: //intentional fallthrough case 8: cout << switchTest << " is an even number" << endl; break; case 1: //intentional fallthrough case 3: //intentional fallthrough case 5: //intentional fallthrough case 7: //intentional fallthrough case 9: cout << switchTest << " is an odd number" << endl; break; default: cout << "Please make sure you entered a number from 0 to 9" << endl; break; } cout << "end of function" << endl; mainOptions();}void whileStatement(){ cout << "while statement function selected!" << endl; int whileTest = 0; while( whileTest <= 100 ) { cout << whileTest << " out of 100!" << endl; whileTest++; } cout << "end of function" << endl; mainOptions();}void forStatement(){ cout << "while statement function selected!" << endl; for ( int i = 0; i <= 100; i++ ) { cout << i << " out of 100!" << endl; } cout << "end of function" << endl; mainOptions();}void doWhileStatement(){ cout << "do statement function selected!" << endl; int doWhileTest = 0; do { cout << doWhileTest << " out of 100!" << endl; doWhileTest++; } while( doWhileTest <= 100 ); cout << "end of function" << endl; mainOptions();}void fileWrite(){ cout << "file write statement function selected!" << endl; ofstream fileWriteTest ( "your new file.txt" ); if ( fileWriteTest.is_open() ) { if( fileWriteTest.good() ) { fileWriteTest << "Wrting this to the file.\n"; } } else { cout << "Unable to open the file"; } cout << "end of function" << endl; mainOptions();}void fileRead(){ cout << "file read statement function selected!" << endl; string line; ifstream fileReadTest ( "your new file.txt" ); if ( fileReadTest.is_open() ) { while ( fileReadTest.good() ) { getline ( fileReadTest, line ); cout << line << endl; } fileReadTest.close(); } else { cout << "Unable to open the file"; } cout << "end of function" << endl; mainOptions();}void inputError(){ cout << "Please make sure you put in a valid number!" << endl; mainOptions();}void mainOptions(){ cout << "\n\n"; cout << "pick a number between 1 and 7 to run a function" << endl; cout << "** 1: ifStatement" << endl; cout << "** 2: switchStatement" << endl; cout << "** 3: whileStatement" << endl; cout << "** 4: forStatement" << endl; cout << "** 5: doWhileStatement" << endl; cout << "** 6: fileWrite" << endl; cout << "** 7: fileRead" << endl;}