cplus 实验一

Posted devin-booker

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cplus 实验一相关的知识,希望对你有一定的参考价值。

//2_4练习.cpp
#include<iostream>
using namespace std;
int main()
{
  int day;
  cout<<"please enter the number between1-7"<<endl;
  cin>>day;
  switch(day)
{
 //注意case 的错误用法
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
      cout<<"workday.Let‘s work hard"<<endl;
      break;
  case 6:
  case 7:
      cout<<"weekend.Let‘s have a rest"<<endl;
      break;
      //若输入不和要求
  default:
     cout<<"you‘ve entered the wrong number "<<endl;
     break;
}
return 0;
}

技术分享图片

技术分享图片

 

技术分享图片

 

 

//2_6.cpp 反序输出数
#include <iostream>
using namespace std;
int main()
{
int num,newnum=0,x=0;
const int y=10;
cout<<"Enter your number"<<endl;
cin>>num;
for(num;num!=0;num/=y)
   {
    x=num%y;
    newnum=newnum*y+x;
   }
   cout<<newnum<<endl;
   return 0;
 }

技术分享图片

技术分享图片

 

实验总结:本次实验为第一次接触c++后进行的编程练习。在对c++一个了解与初步学习中,发现了其源于c而又高于c的一面。在这一章的学习中,发现了其输出输入的不同。在本次实验中运用了for,switch,break。但实验中经历了一些错误。比如case1:case2:不能写成case1:2:并且发现name=cin>>name;并不能运行。本次第一个程序中需要改善的是如果输入数字错误,应再次输入,直到输入正确则开始switch选择.













































以上是关于cplus 实验一的主要内容,如果未能解决你的问题,请参考以下文章

cplus实验一

cplus 实验四

cplus 实验二

OS实验一实验报告

机器学习——实验一

模式识别与图像处理课程实验一:图像处理实验(颜色算子实验SusanHarris角点检测实验 sobel边缘算子检测实验)