一、输入球的中心点和球上某一点的坐标,计算球的半径和体积。ios
1 #include<iostream> 2 #include<math.h> 3 using namespace std; 4 #define Pi 3.1415926 5 6 int main(){ 7 double x,y,z; 8 double o,p,q; 9 cout<<"请输入两组坐标"<<endl; 10 cin>>x>>y>>z>>o>>p>>q; 11 double r; 12 r=sqrt((q-z)*(q-z)+(o-x)*(o-x)+(p-y)*(p-y)); 13 cout<<"半径"<<r<<" 体积"<<4.0/3.0*Pi*r*r*r<<endl; 14 15 16 return 0; 17 }//main
二、 手工创建一个文件,文件种每行包括学号、姓名、性别和年龄。ide
每个属性使用空格分开。文件以下: 01 李江 男 21spa
02 刘唐 男 233d
03 张军 男 19code
04 王娜 女 19blog
根据输入的学号,查找文件,输出学生的信息。ci
1 #include<iostream> 2 #include<string> 3 #include<fstream> 4 using namespace std; 5 6 int main(){ 7 /*已下三行是手动完成的 8 ofstream fout; 9 fout.open("fx2.txt"); 10 fout<<"01 李江 男 21\n02 刘唐 男 23\n03 张军 男 19\n04 王娜 女 19"<<endl; 11 */ 12 13 ifstream fin; 14 fin.open("fx2.txt"); 15 string s; 16 cout<<"请输入学号"<<endl; 17 cin>>s; 18 char num[50]; 19 20 while(fin.getline(num,50)){ 21 if(s[0]==num[0]&&s[1]==num[1]){//学号有两位,分别比较这两位 22 cout<<num<<endl; 23 break; 24 } 25 } 26 27 fin.close(); 28 // fout.close(); 29 return 0; 30 }//main
三、输入年月日,计算该日期是本年的第几天。例如1990年9月20日是1990年的第263天,2000年5月1日是2000年第122天。get
( 闰年:能被400正除,或能被4整除但不能被100整除。每一年一、三、五、七、八、10为大月)string
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 int main(){ 6 int year,month,day,count=0; 7 cout<<"请输入一个日期,如1990 3 2"<<endl; 8 cin>>year>>month>>day; 9 if(year%400==0||year%4==0&&year%100!=0){ 10 for(int i=1;i<month;i++){ 11 cout<<"month"<<i<<endl; 12 if(i==1||i==3||i==5||i==7||i==8||i==10){ 13 14 count+=31; 15 }else if(i==2){ 16 count+=29; 17 }else{ 18 count+=30; 19 } 20 } 21 count+=day; 22 }else{ 23 for(int i=1;i<month;i++){ 24 cout<<"month"<<i; 25 if(i==1||i==3||i==5||i==7||i==8||i==10){ 26 cout<<" 31"<<endl; 27 count+=31; 28 }else if(i==2){ 29 cout<<" 28"<<endl; 30 count+=28; 31 }else{ 32 cout<<" 28"<<endl; 33 count+=30; 34 } 35 } 36 count+=day; 37 38 } 39 cout<<year<<"年"<<month<<"月"<<day<<"日是"<<year<<"的第"<<count<<"天"<<endl; 40 41 return 0; 42 }//main