/* File Name: assignone.cpp * Code Documented by Bhavani Prasad Sangannagari * This program is coded for the first assignment * that illustrates the concept of multi-threaded * programming * This program shows how to create a new thread * using the _beginthread function. The actual work * in this program is done in the routine centofahr. This * routine takes a single argument (a void pointer) that * it casts to a float. The routine then calculates the * temperature in fahrenheit then prints the sum. * The main program converts celcius temperature into fahrenheit * using the child thread and again computes the same without * using the child thread. * The formula c/100 = (f-32)/180 is used for conversion by the * function centofahr */ #include #include #include // function declaration void centofahr(void *); // global flag used to ensure main thread stops still child thread ends char gflg = 'n'; void main() { // cent accepts centigrade temperature from the user // flg is used to verify if user wants to do more conversions float cent; char flg = 'y'; cout<<"\n\tPROGRAM TO CONVERT TEMPERATURE FROM CENTIGRADE SCALE TO FAHRENHEIT SCALE"; // this loop is used to repeat the program // if the user wants to calculate more than one // temperature conversions based on the value of flg // if entered y repeats else terminates program while(flg == 'y') { // accept input in celcius cout<<"\n please enter the temperature in celcius :\t"; cin>>cent; cout<<"\n This result is calculated using a thread"; // beginthread function is used to start a new thread // that calculates equivalent temperature in fahrenheit // with default stack, cent as argument and using centofahr function _beginthread(centofahr,0,(void *) ¢); // this while loop is used to ensure the main thread waits // till the child thread completes execution while(gflg == 'n'); cout<<"\n this result is obtained without using a thread"; centofahr((void *) ¢); cout<<"\n would u like to do another convertion ? enter y or n :"; cin>>flg; gflg = 'n'; } } /* function : centofahr takes void pointer as argument does required calculation prints the result to the console */ void centofahr(void * celcius) { float fahr, temp; temp = *(float *) celcius; fahr = (temp * 180)/100 + 32; cout<<"\n"<<" In fahrenheit scale is "<