// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 4: File input/ouput, // random number generators and output formating // Date: January 12, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is to ractice rand(), srand() and // output formating with help of . It also practice // file input and output. // // You need to create an input file, named with "lab_4_data.txt" with // the following integers "23 456 3000 578 9876". // // You do not need to create an output file, because the file open call // will do this for you. // // Compile and run your program. When everything is fine, // print your .cpp file and turn it to me or the TA. // ***************************************************************** #include < iostream > #include #include < string > #include < cmath> #include #include using namespace std; void showMenu(); int main( ) { //file declaration ifstream inputSeedsFile;//input file with random seeds ofstream outTableFile, //output file to store square root and logarithm table outCalendarFile; //output file to store the calendar //variable declarations unsigned seed; //random seed int x, totalNumber; //x holds int values, totalNumbers holds the number of int values double sqrtResult, //store square roots logResult; //store base-10 logrithmic values int choice; //store choice value (1, 2, 0r 3) char option; //store option valye (y/n) int dice1, dice2, //dice numbers sum, guess; //the sum of two dices and the guessed sum //open the input file inputSeedsFile.open("lab_4_data.txt"); //open the output files outTableFile.open("lab_4_output.txt"); outCalendarFile.open("Lab_4_outputCalendar.txt"); while ( true ) { showMenu(); //show menu cin>>choice; //get the user's choice //build a log and base-10 logrithmic table if (choice == 1) // { cout<<"How many numbers do you want to play? "; cin>>totalNumber; //totalNumber shall be >= 1 if (totalNumber < 1) { cout<<"The total number must be greater or equal to 1. "; } else //build the table when totalNumber >= 1 { //prepare the outfile format //set decimal format with 4 decimal digits outTableFile<(i)) //print column 2 <(i))<>seed; //set the random seed srand(seed); //roll the first dice dice1 = 1 + rand()%6; cout<<"Rolled dice one ........................"< "<>guess; if (guess == sum) { cout<<"You are a winner!" < *********************************************************************************************/ if (choice == 3 ) { } cout<<"Do you want to play again (y/n)? "; cin>>option; if (option !='y') { cout<<"Bye bye!"< "; return; }