NEFU C++课程实验2(锐格)(不全)

前言:这些题都比较简单,我写的不是很好,没有很仔细听课,仅供大家参考。

5349、

#include<iostream>
#include<string>
using namespace std;
class Stock{
    string stockcode;
    int quan;
    float price;
    
public:
    Stock(string na,int q=1000,float p=8.98){
            stockcode=na;
            quan=q;
            price=p;
        }
    void print(){
        cout<<"stockcode is "<<this->stockcode<<" ";
        cout<<"quan is "<<this->quan<<" ";
        cout<<"price is "<<this->price<<endl;
    }
};
int main(){
    Stock s1("600001",3000,5.67);
    Stock s2("600001");
    s1.print();
    s2.print();


}

5348、

#include<iostream>
using namespace std;
class book{
    int qu;
    int price;
public:
    book(int n){
        qu=n;
        price=qu*10;
    }
    void show(){
        cout<<qu*price<<endl;
    }

};
int main(){
    book p[5]={1,2,3,4,5};
    for(int i=0;i<5;i++){
        cout<<"p["<<i<<"]"<<" is ";
        p[i].show();
    }
}

 5347、

和5348一模一样不知道学校咋出的题

#include<iostream>
using namespace std;
class book{
    int qu;
    int price;
public:
    book(int n){
        qu=n;
        price=qu*10;
    }
    void show(){
        cout<<qu*price<<endl;
    }

};
int main(){
    book p[5]={1,2,3,4,5};
    for(int i=0;i<5;i++){
        cout<<"b["<<i<<"]"<<" is ";
        p[i].show();
    }
}

 5346、

#include<iostream>
using namespace std;
class cylinder{
    double r,h;
    double v;
public:
    cylinder(double r1,double h1){
        r=r1;
        h=h1;
    }
    double sum(){
        v=3.14*r*r*h;
    }
    double vol(){
        return v;
    }
};
int main(){
    double x,y;
    cin>>x>>y;
    cylinder c(x,y);
    c.sum();
    double v;
    v=c.vol();
    cout<<"volume is "<<v<<endl;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小李小于

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值