2003年北理复试上机题

 

历年北京理工大学复试上机题题目汇总:

http://blog.youkuaiyun.com/u014552756/article/details/78505845

 

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

 

 

#include<iostream>
#include<math.h>
using namespace std;

double const pi=3.1415;

int main()
{
    double a,b,c,x1,y1,z1,r;
    cout<<"请输入球心坐标:"<<endl;
    cin>>a>>b>>c;
    cout<<"请输入球上任意一点的坐标:"<<endl;
    cin>>x1>>y1>>z1;
    r=sqrt(pow(x1-a,2)+pow(y1-b,2)+pow(z1-c,2));
    cout<<"球的半径为:"<<r<<endl<<"球的体积为:"<<(4/3.0)*pi*pow(r,3)<<endl;

    return 0;
}

 

2、手工建立一个文件,文件种每行包括学号、姓名、性别和年龄。每一个属性使用空格分开。文件如下:

01 李江男 21

02 刘唐男 23

03 张军男 19

04 王娜女 19

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

 

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
    int a,b;
    int num;
    string s1,s2;

    cout<<"请输入学生信息,格式:学号 姓名 性别 年龄,以学号0结束"<<endl;
    ofstream out("student.txt");
    while(cin>>a>>s1>>s2>>b)
    {
        if(a==0)
            break;
        out<<a<<" "<<s1<<" "<<s2<<" "<<b<<endl;
    }

    cout<<"请输入要查询的学生考号:"<<endl;
    ifstream in("student.txt");
    cin>>num;
    int k=0;
    while(!in.eof())
    {
        in>>a>>s1>>s2>>b;
        if(in.fail())
            break;
        if(a==num)
        {
            k=1;
            cout<<<<"学号"<<a<<"对应的姓名为:"<<s1<<endl<<"性别为:"<<s2<<endl<<"年龄为:"<<b<<endl;
        }
    }
    if(in.eof()&&k==0) cout<<"无此学生的信息"<<endl;

    return 0;
}

3、输入年月日,计算该天是本年的第几天。例如1990 年 9 月 20 日是 1990 年的第 263 天,2000年 5 月 1 日是 2000 年第 122 天。(闰年:能被 400整除,或能被 4 整除但不能被 100 整除。每年 1、3、5、7、8、10 为大月)

 

 

#include<iostream>
using namespace std;

int main()
{
    int year,month,day;
    int i,k,s=0;
    cout<<"请输入日期:"<<endl;
    cin>>year>>month>>day;

    if(year%400==0||(year%4==0&&year%100!=0))
    {
        cout<<"这是一个闰年:"<<endl;
        if(month==1)
            cout<<"这个日期是"<<year<<"年"<<"的第"<<day<<"天"<<endl;
        else
        {
            for(i=1; i<month; i++)
            {
                if(i==1||i==3||i==5||i==7||i==8||i==10)
                    k=31;
                if(i==2)
                    k=29;
                else if(i==4||i==6||i==9||i==11)
                    k=30;
                s=s+k;
            }
            cout<<"这个日期是"<<year<<"年"<<"的第"<<s+day<<"天"<<endl;
        }
    }
    else
    {
        cout<<"这是一个平年:"<<endl;
        if(month==1)
            cout<<"这个日期是"<<year<<"年"<<"的第"<<day<<"天"<<endl;
        else
        {
            for(i=1; i<month; i++)
            {
                if(i==1||i==3||i==5||i==7||i==8||i==10)
                    k=31;
                if(i==2)
                    k=28;
                else if(i==4||i==6||i==9||i==11)
                    k=30;
                s=s+k;
            }
            cout<<"这个日期是"<<year<<"年"<<"的第"<<s+day<<"天"<<endl;
        }
    }

    return 0;
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值