前二章作业

2.29:

#include<iostream>
using namespace std;
int main()
{
	int*p=new int[20];
	p[0]=1;p[1]=1;
	for(int i=2;i<20;i++)
		p[i]=p[i-2]+p[i-1];
	for(int j=0;j<20;j++)
		cout<<p[j]<<endl;
	delete p;
	system("pause");
	return 0;
}



2.30:

#include<iostream>
#include<cmath>
using namespace std;
int sroot(int i)
{
	return sqrt(i*1.0);
}
long sroot(long j)
{
	return sqrt(j*1.0);
}
double sroot(double k)
{
	return sqrt(k);
}
int main()
{
	int i=99;
	long j=9999;
	double k=0.99;
	cout<<i<<"的二次平方为:"<<sroot(i)<<endl;
	cout<<j<<"的二次平方为:"<<sroot(j)<<endl;
	cout<<k<<"的二次平方为:"<<sroot(k)<<endl;
	system("pause");
	return 0;
}


定义学生类:

#include <iostream>     
using namespace std;
class Student
{
private:    
    int num; 
    char name[20];   
    int english;  
    int chinese;  
    int math;  
public:    
    void input_data()    
    {   cout<<"请输入学号:";
	    cin>> num;
        cout<<"请输入您的姓名:";
	    cin>>name;  
        cout<<"请输入您的语文成绩:";
        cin>>chinese;       
        cout<<"请输入您的英语成绩:";
        cin>>english;   
        cout<<"请输入您的数学成绩:";
        cin>>math;   
    }    
    void display( )    
    {
		cout<<"您的学生信息如下:"<<endl;
		cout<<"学号"<<'\t'<<"姓名"<<'\t'<<"语文"<<'\t'<<"英语"<<'\t'<<"数学"<<endl;
		cout<<num<<'\t'<<name<<'\t'<<chinese<<'\t'<<english<<'\t'<<math<<endl;
    }    
};    
int main()    
{    
    Student stu1;             
    stu1.input_data();           
    stu1.display();                      
    system("pause");  
    return 0;    
}    


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值