⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c01.cpp

📁 一个”学生作业“的C++大程序。有菜单
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include<iostream.h>
#include<stdio.h>
#include<string.h>
void liu()
{
	enum color{white,black=100,red,blue,green=300};
	cout<<"blue的值是:"<<blue<<endl;
}
void nine()
{
	cout<<"表达式201/4的值是:"<<201/4<<endl;
	cout<<"表达式201%4的值是:"<<201%4<<endl;
	cout<<"表达式201/4.0的值是:"<<201/4.0<<endl;
}
void shi()
{
	int a=30;
	int b,c;
	b=a++;
	c=++a;
	cout<<"a="<<a<<endl;
	cout<<"b="<<b<<endl;
    cout<<"c="<<c<<endl;
}
void dishier()
{
	int n;
	for(n=0;n<100;n++)
	cout<<"n="<<n<<endl;
}
void shisan()
{
	int n;
	cout<<"结果是:"<<endl;
	for(n=100;n<=200;n+=2)
	cout<<"n="<<n<<endl;	
}
void shiqi()
{
	int i;
	int j;
	i=10;
	j=20;
	cout<<"i+j="<<i+j<<endl;
}
void ershi()
{
	int i;
    char ch;
    cout<<"the chars are:"<<endl;
    for(i=32;i<=127;i++)
	{
       ch=i;
       cout<<ch<<endl;
	}
}
void ershiyi()
{
	unsigned int x;
	unsigned int y=100;
	unsigned int z=50;
	x=y-z;
	cout<<"Difference is:"<<x;
	x=z-y;
	cout<<"\nNow difference is:"<<x<<endl;
}
void ershier()
{
    int myage=39;
    int yourage=39;
    cout<<"I am:"<<myage<<"years old.\n";
    cout<<"Your are:"<<yourage<<"years old.\n";
    myage++;
    ++yourage;
    cout<<"one year passes...\n";
    cout<<"I am:"<<myage<<"years old.\n";
    cout<<"Your are:"<<yourage<<"years old.\n";
    cout<<"another year passes...\n";
    cout<<"I am:"<<myage++<<"years old.\n";
    cout<<"Your are:"<<++yourage<<"years old.\n";
    cout<<"let's print again.\n";
    cout<<"I am:"<<myage<<"years old.\n";
    cout<<"Your are:"<<yourage<<"years old.\n";
}
void ershiwu()
{
	int i,j,k;
	i=2<3&&6<9;
	j=!(4<7);
	k=!(3>5)||(6<2);
	cout<<"表达式2<3&&6<9的值是:"<<i<<endl;
	cout<<"表达式!(4<7)的值是:"<<j<<endl;
    cout<<"表达式!(3>5)||(6<2)的值是:"<<k<<endl;
}
void ershiliu()
{
	int a,b,c;
	int i,j,k,l;
	a=1,b=2,c=3;
	i=a|b-c;
	j=a^b&-c;
	k=a&b|c;
	l=a|b&c;
    cout<<"表达式a|b-c的值是:"<<i<<endl;
	cout<<"表达式a^b&-c的值是:"<<j<<endl;
    cout<<"表达式a&b|c的值是:"<<k<<endl;
    cout<<"表达式a|b&c的值是:"<<l<<endl;
}
void ershiqi()
{
	int a=1;
	int i,j,k,l;
	i=!a|a;
	j=~a|a;
	k=a^a;
	l=a>>2;
    cout<<"表达式!a|a的值是:"<<i<<endl;
	cout<<"表达式~a|a的值是:"<<j<<endl;
    cout<<"表达式a^a的值是:"<<k<<endl;
    cout<<"表达式a>>2的值是:"<<l<<endl;
}
void rain()
{
    char c;
    cout<<"现在正在下雨吗?(请用户输入y或n)"<<endl;
    cin>>c;
    switch(c)
	{
      case 'y': cout<<"现在正在下雨"<<endl;      break;
      case 'n': cout<<"现在正没有下雨"<<endl;    break;      
	  default:        rain();                    break;
	}
}
void ershiba()
{
    rain();
}
void ershijiu()
{
	int m;
	cout<<"你考试考了多少分:"<<endl;
	cin>>m;
	if(m>=90&&m<=100)
	   cout<<"你的成绩是:优"<<endl;
	if(m>=80&&m<90)
	   cout<<"你的成绩是:良"<<endl;
	if(m>=60&&m<80)
	   cout<<"你的成绩是:中"<<endl;
	if(m>>0&&m<60)
	   cout<<"你的成绩是:差"<<endl;
}
void dierzhang()
{   
	int c;
	cout<<"======请问,您想看哪道题:======="<<endl;
    cout<<"==========第6题=================="<<endl;
    cout<<"==========第9题=================="<<endl;
    cout<<"==========第10题================="<<endl;
    cout<<"==========第12题================="<<endl;
	cout<<"==========第13题================="<<endl;
    cout<<"==========第17题================="<<endl;
	cout<<"==========第20题================="<<endl;
	cout<<"==========第21题================="<<endl;
	cout<<"==========第22题================="<<endl;
    cout<<"==========第25题================="<<endl;
	cout<<"==========第26题================="<<endl;
	cout<<"==========第27题================="<<endl;
    cout<<"==========第28题================="<<endl;
	cout<<"==========第29题================="<<endl;
    cout<<"==========0(返回主菜单)========"<<endl;
	cin>>c;
	switch(c)
	{
	  case 6: liu();         dierzhang();    break;
      case 9: nine();        dierzhang();    break;
	  case 10: shi();        dierzhang();    break;
      case 12: dishier();    dierzhang();    break;
	  case 13: shisan();     dierzhang();    break;
      case 17: shiqi();      dierzhang();    break;
	  case 20: ershi();      dierzhang();    break;
	  case 21: ershiyi();    dierzhang();    break;
      case 22: ershier();    dierzhang();    break;
      case 25: ershiwu();    dierzhang();    break;
	  case 26: ershiliu();   dierzhang();    break;
      case 27: ershiqi();    dierzhang();    break;
	  case 28: ershiba();    dierzhang();    break;
	  case 29: ershijiu();   dierzhang();    break;
	  case 0:                                break;
	}
}

void qi()
{
	unsigned short int a,b;
    short int c;
    cout<<"请输入两个数:"<<endl;
    cin>>a>>b;
    cout<<"结果是:"<<endl;
    if(b==0)
	   cout<<"严重警告!0不能做除数!"<<endl;
	else
       c=a/b;
       cout<<c<<endl; 
    
     
}
void ba()
{
	float F;
	float C;
    cout<<"请输入华氏温度:"<<endl;
	cin>>F;
	C=(F-32)*5/9;
    cout<<"相应的摄氏温度是:"<<C<<endl;
}
void shisi()
{
	int i,fib[20];
	fib[0]=fib[1]=1;
	for(i=2;i<20;i++)
		fib[i]=fib[i-1]+fib[i-2];
	puts("\n");
	for(i=0;i<20;i++)
	{
		cout<<fib[i]<<endl;
		if((i+1)%5==0)
		    puts("\n");
	}
}
void disanzhang()
{  
   int c;
   cout<<"====请问,您想看哪道题:======="<<endl;
   cout<<"========第7题=================="<<endl;
   cout<<"========第8题=================="<<endl;
   cout<<"========第14题================="<<endl;
   cout<<"========0(返回主菜单)========"<<endl;
   cin>>c;
   switch(c)
   {
	 case 7: qi();       disanzhang();    break;
	 case 8: ba();       disanzhang();    break;
	 case 14: shisi();   disanzhang();    break;
     case 0:                              break;
   }
}

class rectangle
{
 public:
    void setdata(int a,int b,int x,int y);
	void showarea();
 private:
	int a1,b1,x1,y1,s1;
};
void rectangle::setdata(int a,int b,int x,int y)
{
	a1=a;
	b1=b;
	x1=x;
	y1=y;
	s1=(x-a)*(y-b);
}
void rectangle::showarea()
{      
	cout<<"矩形的面积是:"<<s1<<endl;
    
}
void dijiu()
{   rectangle abc;
    int aa,bb,xx,yy;
	cout<<"请输入矩形的左下角坐标(a,b)和右下角坐标(x,y)"<<endl;
	cin>>aa>>bb>>xx>>yy;
	abc.setdata(aa,bb,xx,yy);
	abc.showarea();
 }
class juxing
{
 public:
	void setdata(int l,int w);
	void showarea();
 private:
	int l1,w1,s;
};
void juxing::setdata(int l,int w)
{
	l1=l;
	w1=w;
	s=l*w;
}
void juxing::showarea()
{
	cout<<"矩形的面积为:"<<s<<endl;
}
void dishiyi()
{   
	juxing myjuxing;
    int ll,ww;
	cout<<"请输入矩形的长和宽:"<<endl;
	cin>>ll>>ww;
	myjuxing.setdata(ll,ww);
    myjuxing.showarea();
}
class circle
{
 public:
	void setradius(double r=0);
	void getarea();
 private:
	double radius,s;
};
void circle::setradius(double r)
{
	radius=r;
	s=3.14159*r*r;
}
void circle::getarea()
{   
	cout<<"圆的面积是:"<<s<<endl;
}
void dishisan()
{ 
    circle mycircle;
    double r1;
    cout<<"请输入圆的半径:"<<endl;
    cin>>r1;
    mycircle.setradius(r1);
    mycircle.getarea();
}
class tree
{
 public:
	void grow(int a,int y);
	void age();
 private:
	int ages,years;
};
void tree::grow(int a,int y)
{
	ages=a;
	years=y;
	ages=a+y;
}
void tree::age()
{
	cout<<"这棵树现在的年龄是:"<<ages<<endl;
}
void dishisi1()
{
    tree mytree;
    int aa,bb;
    cout<<"请输入这棵树的树龄和这棵树长的年数:"<<endl;
    cin>>aa>>bb;
    mytree.grow(aa,bb);
    mytree.age();
}
void disizhang()
{
	int c;
    cout<<"======请问,您想看哪道题:======="<<endl;
	cout<<"==========第9题=================="<<endl;
	cout<<"==========第11题================="<<endl;
	cout<<"==========第13题================="<<endl;
	cout<<"==========第14 题================"<<endl;
    cout<<"==========0(返回主菜单)========"<<endl;
	cin>>c;
	switch(c)
	{
	    case 9: dijiu();       disizhang();    break;
	    case 11: dishiyi();    disizhang();    break;
		case 13: dishisan();   disizhang();    break;
		case 14: dishisi1();   disizhang();    break;
		case 0:                                break;
	}
	  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -