C++课堂练习一

课程内容: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;
}

posted @ 2019-08-31 14:15  liqing45  阅读(216)  评论(0编辑  收藏  举报