user-0 提问: 周五的考试题 大家帮忙看看

回复:
user: user-0
content: #include <cstdlib> #include <iostream> #include <iomanip> /* run this program using the console pauser or add your own getch, system("pause") or input loop */  using namespace std;  double check_input() { 	double input_value; 	cin>>input_value; 	if ((input_value<0) || (input_value > 1000)) { 		cout << "Incorrect input, please enter a value between $0 and $1000: $"; 		cin>>input_value; 	} 	return input_value; }  int main(int argc, char** argv) { 	double input_quarter, prev_balance; 	double mon1[3];							// monthly puchases for each store, going in order of Sears, Canadian Tire and The Bay 	double mon2[3]; 	double mon3[3]; 	string q1[3] = {"January", "February", "March"}; 	string q2[3] = {"April", "May", "June"}; 	string q3[3] = {"July", "August", "September"}; 	string q4[3] = {"October", "November", "December"}; 	string temp_month; 	double input_array[3];										// temp input_array to store inputs before being transfered to mon1, mon2 or mon3 	double sears_total, canadian_tire_total, the_bay_total, minimum_payment, quarterly_total, balance_owing; 	int go_again; 	 	do { 		cout <<"Please enter the yearly quarter from one of the following (1,2,3,4): "; 		cin >> input_quarter; 		while((input_quarter < 1) || (input_quarter > 4)) { 			cout << "Wrong input. Pleae input one of the following '1,2,3,4': "; 			cin>> input_quarter; 		} 		 		cout <<"Please enter prev balance between $0 - $1000: $"; 		prev_balance = check_input(); 		 	 		for (int j = 0; j < 3; j++) {							// selects month 		 			if (input_quarter == 1) 							// selects month based on year quarter 				temp_month = q1[j]; 			else if (input_quarter == 2) 				temp_month = q2[j]; 			else if (input_quarter == 3) 				temp_month = q3[j]; 			else  				temp_month = q4[j]; 			 			cout<<"\nPlease input Sears purchases for "<<temp_month<<": "; 			input_array[0] = check_input(); 			cout<<"\nPlease input Canadian Tire purchases for "<<temp_month<<": "; 			input_array[1] = check_input(); 			cout<<"\nPlease input The Bay purchases for "<<temp_month<<": "; 			input_array[2] = check_input(); 			if (j == 0) {								// monthly purchases for the 1st month in curretn quarter in order of Sears, Canadian Tire, and The Bay 				for (int k = 0; k < 3; k++) 					mon1[k] = input_array[k]; 			} 			if (j == 1) {									// monthly purchases for the 2nd month in curretn quarter in order of Sears, Canadian Tire, and The Bay 				for (int k = 0; k < 3; k++) 					mon2[k] = input_array[k]; 			} 			else {		        								// monthly purchases for the 3rd month in curretn quarter in order of Sears, Canadian Tire, and The Bay 				for (int k = 0; k < 3; k++) 					mon3[k] = input_array[k]; 			} 		} 		 		sears_total = mon1[0]+mon2[0]+mon3[0]; 		canadian_tire_total = mon1[1]+mon2[1]+mon3[1]; 		the_bay_total = mon1[2]+mon2[2]+mon3[2]; 		quarterly_total = sears_total + canadian_tire_total + the_bay_total; 		balance_owing = prev_balance + quarterly_total; 		minimum_payment = balance_owing*0.1; 		 		cout << "\n\n\nMonth\t\tSears\t\tCanadian Tire\t\tThe Bay"<<endl; 		for (int j = 0; j < 3; j++) { 			if (input_quarter == 1) 				temp_month = q1[j]; 			else if (input_quarter == 2) 				temp_month = q2[j]; 			else if (input_quarter == 3) 				temp_month = q3[j]; 			else  				temp_month = q4[j]; 			 			if (j == 0) 				cout <<fixed<<setprecision(2)<<temp_month<<"\t\t$"<<mon1[0]<<"\t\t   $"<<mon1[1]<<"\t\t    $"<<mon1[2]<<endl;	// fixed<<setprecision(2) truncates minimum_payment after decimal point 			if (j == 1) 				cout <<fixed<<setprecision(2)<<temp_month<<"\t\t$"<<mon2[0]<<"\t\t   $"<<mon2[1]<<"\t\t    $"<<mon2[2]<<endl; 			if (j == 2) 				cout <<fixed<<setprecision(2)<<temp_month<<"\t\t$"<<mon3[0]<<"\t\t   $"<<mon3[1]<<"\t\t    $"<<mon3[2]<<endl; 		} 		cout<<"Total\t\t$"<<sears_total<<"\t\t  $"<<canadian_tire_total<<"\t\t    $"<<the_bay_total<<endl; 		cout<<"\nQuarterly Total: $"<<quarterly_total<<endl; 		cout <<"Balance Owing: $"<< balance_owing<<endl; 		cout<<"Minimum Payment: $"<<fixed<<setprecision(2)<<minimum_payment<<endl;	 		 		cout << "\nDo you want to do another quarter? (1 for yes, 2 for no): "; 		cin>> go_again; 		while ((go_again < 1) || (go_again > 2)) { 			cout<<"Incorrect input, please enter 1 or 2: "; 			cin>> go_again; 		} 	}while(go_again == 1); 		 	return EXIT_SUCCESS; }

user: user-1
content: 引用 楼主 u013670102 的回复:You work for the Zippy Credit Card Company and have been assigned to develop a C program that will do the following:  A. Prompt an operator to input two values:   o The number (1-4) of the current quarter of the year (The 1st quarter is January to March)   o A previous balance owing between $0 - $1,000  B. Will then prompt for monthly total purchases from each of three stores, for each month of the current quarter. The store names are Sears, Canadian Tire, and The Bay. Monthly purchases must be between $0 - $1,000  C. Will output:    o Monthly purchases from each store    o A quarterly total for each store    o An overall quarterly total for all three stores    o A new balance owing    o A minimum 10% payment (calculated from the new balance owing)  Sample Output (2nd Quarter):  Month     Sears       Canadian Tire     The Bay April     $100.10     $103.94           $15.00 May       $93.40      $120.00           $140.75 June      $140.00     $20.05            $86.39 Total     $333.50     $243.99           $242.14  Quarterly Total: $819.63 Previous Balance: $983.54 Balance Owing: $1803.17 Minimum Payment: $180.32  D. After outputting the results for the specified quarter the program will prompt the operator to either do another quarter (i.e. loop back to step A) or exit the program.  Evaluation Criteria: Program must compile without errors or warnings Comments are clear and appropriate 10% Variable names and initialization follow good practices 10% Prompts are clear 10% Invalid entries are handled appropriately 10% Program calculates correctly 30% The output is appropriately formatted 30%说中文!