第一题:
#includeusing namespace std; int main() { const int INCH_PER_FEET = 12; cout << "please enter your height:___bbb"; //b的含义是,将光标从当前位置向前(左)移动一个字符(遇到n或r则停止移动) int height; cin >> height; cout << "your height is " << height / INCH_PER_FEET << " feet and " << height % INCH_PER_FEET << " inches"; return 0; }
第三题
#includeusing namespace std; int main() { float degrees, minutes, seconds; cout << "Enter a latitude in degrees,minutes and seconds:"<< endl; cout << "First,enter the degreees: "; cin >> degrees; cout << "Next,enter the minutes of arc:"; cin >> minutes; cout << "Finally,enter the seconds of arc:"; cin >> seconds; float result=degrees + (minutes / 60.0) + (seconds / (60.0 * 60.0)); cout << degrees << " degrees," << minutes << " minutes," << seconds << " seconds= " << result<<" degrees"; return 0; }
第四题:
#includeusing namespace std; int main() { const int HOUR_PER_DAY = 24; //1天有24小时; const int MINUTE_PER_HOUR = 60; //1小时有60分钟; const int SECOND_PER_MINUTE = 60; //1分钟有60秒; long long second; cout << "Enter the number of seconds: "; cin >> second; cout << second << " seconds = "; cout << second / (HOUR_PER_DAY * MINUTE_PER_HOUR * SECOND_PER_MINUTE); cout << " days, "; cout << second / (SECOND_PER_MINUTE * MINUTE_PER_HOUR) % HOUR_PER_DAY; cout << " hours, "; cout << second % (SECOND_PER_MINUTE * MINUTE_PER_HOUR) / SECOND_PER_MINUTE; cout << " minutes, "; cout << second % SECOND_PER_MINUTE; cout << " seconds" << endl; return 0; }
第五题:
#includeusing namespace std; int main() { long long world, us; cout << "Enter the world's population:"; cin >> world; cout << "Enter the population of the US:"; cin >> us; cout << "The population of the US is " << double(us) / world * 100LL<< " % of the world population"; return 0; }
第三题
#include#include using namespace std; int main() { const int ArSize = 20; char fname[ArSize]; char lname[ArSize]; cout << "Enter your first name: "; cin.getline(fname, ArSize); cout << "Enter your last name: "; cin.getline(lname, ArSize); int len = strlen(fname) + strlen(lname) + 10; char name[10]; strcpy(name, lname); strcat(name, ", "); strcat(name, fname); cout << "Here's the information in a single string: "; cout << name << endl; return 0; }
第八题:
#include#include using namespace std; struct piza { string band; float radius; float weight; }; int main() { piza *p=new piza; getline(cin, p->band); cin >> p->radius; cin >> p->weight; cout << "披萨的品牌:" << p->band << endl; cout << "披萨的直径:" << p->radius << endl; cout << "披萨的重量:" << p->weight << endl; return 0; }



