北京理工计算机 上机复试2003年

1、输入球的中心点和球上某一点的坐标,计算球的半径和体积。

 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
2003_01.cpp

2、  手工建立一个文件,文件种每行包括学号、姓名、性别和年龄。

   每一个属性使用空格分开。文件如下:   01 李江 男 21

                     02 刘唐 男 23

                     03 张军 男 19

                     04 王娜 女 19

   根据输入的学号,查找文件,输出学生的信息。

 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
2003_02.cpp

3、输入年月日,计算该日期是本年的第几天。例如1990年9月20日是1990年的第263天,2000年5月1日是2000年第122天。

    ( 闰年:能被400正除,或能被4整除但不能被100整除。每年1、3、5、7、8、10为大月)

 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
2003_03.cpp

 

转载于:https://www.cnblogs.com/Alan-Wei/p/6432893.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值