C++作业3


一、问题及代码

/* 
* 文件名称: month.cpp
* 作    者:  任琦璇
* 完成日期:   2017   年   3  月  24  日 
* 版 本 号:v1.0 
* 对任务及求解方法的描述部分:
* 输入描述: 输入年份和月份 
* 问题描述: 使用if语句等进行判断
* 程序输出: 输出本月有多少天 
* 问题分析: 略
* 算法设计:  使用到if语句
*/  
#include <iostream>
using namespace std;
int main ()
{
	int year,month;
	cout<<"输入年份和月份"<<endl;
	cin>>year>>month;
	
	if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
		cout<<"本月31天"<<endl;
	else if(month==4||month==6||month==9||month==11)cout<<"本月30天"<<endl;
	else if (year%4==0&&year%100!=0||year%400==0)
		cout<<"本月29天"<<endl;
	else cout<<"本月28天"<<endl;
	return 0;
}

二、运行结果

一、问题及代码

/* 
* 文件名称:Project3.cpp
* 作    者:  任琦璇
* 完成日期:   2017   年  3   月 24   日 
* 版 本 号:v1.0 
* 对任务及求解方法的描述部分:
* 输入描述:  输入存款金额并选择存款种类
* 问题描述: 对输入金额及种类进行判断,再进行计算
* 程序输出:  利息(不计利息税)和本息合计
* 问题分析: 根据选择的存款种类,确定利率和存期后计算
* 算法设计:  使用switch语句等
*/  
#include <iostream>
using namespace std;
int main ()
{
	double money,interest,sum;
	char number;
	cout<<"欢迎使用利息计算器!"<<endl;
	cout<<"请输入存款金额:";
	cin>>money;
	
	cout<<"======存款期限======"<<endl;
	cout<<"1.3个月"<<endl;
	cout<<"2.6个月"<<endl;
	cout<<"3.一年"<<endl;
	cout<<"4.二年"<<endl;
	cout<<"5.三年"<<endl;
	cout<<"6.五年"<<endl;
	cout<<"请输入存款期限的代号:";
	cin>>number;
	cout<<"到期利息为";
	switch (number)
	{
	case '1':interest=money*0.0310*0.25;
		cout<<interest<<"元,";
		break;
	case '2':interest=money*0.0330*0.5;
		cout<<interest<<"元,";
		break;
	case '3':interest=money*0.0350;
		cout<<interest<<"元,";
		break;
	case '4':interest=money*0.0440*2;
		cout<<interest<<"元,";
		break;
	case '5':interest=money*0.0500*3;
		cout<<interest<<"元,";
		break;
	case '6':interest=money*0.0550*5;
		cout<<interest<<"元,";
		break;
	default:cout<<"error!\n";
	}
	sum=interest+money;
	cout<<"本息合计共"<<sum<<"元。"<<endl;
	cout<<"感谢您的使用,欢迎下次光临!"<<endl;
	return 0;
}


 

二、运行结果

一、问题及代码

/* 
* 文件名称:  1.cpp
* 作    者:  任琦璇
* 完成日期:    2017  年   4  月  7  日 
* 版 本 号:v1.0 
* 对任务及求解方法的描述部分:
* 输入描述:  输入x的值
* 问题描述: 分段函数求值
* 程序输出:  输出求出的y 
* 问题分析: 使用到选择结构
* 算法设计:  使用if语句
*/  
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	double x,y,z;
	cout<<"请输入x的值"<<endl;
	cin>>x;
	if (x<2)
		cout<<"y的值为"<<x<<endl;
	else if (x<6)
	{
		y=x*x+1;
		cout<<"y的值为"<<y<<endl;
	}
	else if (x<10)
	{
		y=sqrt(x+1);
		cout<<"y的值为"<<y<<endl;
	}
	else	
	{
		z=x+1;
		y=1/z;
		cout<<"y的值为"<<y<<endl;
	}
	return 0;
}


二、运行结果





猜你喜欢

转载自blog.csdn.net/renqixuan/article/details/69545974