码迷,mamicode.com
首页 > 编程语言 > 详细

C++课堂练习一

时间:2019-08-31 14:57:45      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:贺卡   org   ddr   image   span   内容   ref   line   style   

课程内容:https://www.icourse163.org/course/XJTU-46006

1、生日贺卡

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

int main(){
    char addressee[50], sender[50];
    cout << "请输入收信人:" << endl;
    cin.getline(addressee, 50);
    cout << "请输入寄信人:" << endl;
    cin.getline(sender, 50);
    cout << "#################################" << endl;
    cout << addressee << endl;
    cout << endl;
    cout << "Happy birthday to you!" << endl;
    cout << endl;
    cout << "    sincerely yours " << sender << endl;
    cout << "#################################" << endl;
    return  0;   
}

技术图片

2、加法计算器

#include<iostream>
using namespace std;
int main(){
    int a, b;
    int c;
    cout << "计算a+b,请输入a,b:" << endl;
    cin >> a >> b;
    c = a + b;
    cout << "c = " << c << endl;
    return 0;
}

技术图片

3、计算本息和

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double money, years, rate, sum;
    cout << "请输入本金,年份,利率:" << endl;
    cin >> money >> years >> rate;
    while (money >= 0) 
    {
        sum = money * pow((1 + rate), years);
        cout << "本息和 = " << sum << endl;
        cout << "请输入本金,年份,利率(本金小于0时退出):" << endl;
        cin >> money >> years >> rate;
    }
    return 0;
}

技术图片

C++课堂练习一

标签:贺卡   org   ddr   image   span   内容   ref   line   style   

原文地址:https://www.cnblogs.com/liqing45/p/11438861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!