C++高手帮个忙~急急急急急!!!

2024-11-23 16:46:27
推荐回答(3个)
回答1:

1、
#include
using namespace std;

enum Color
{
RED,BLUE,GREEN
};
int main()
{
for(int i = RED; i<=GREEN; i++)
for(int j = RED; j<=GREEN; j++)
for(int k=RED; k<=GREEN; k++)
if(i!=j && i!=k && j!=k)
cout<return 1;
}

2、
#include
using namespace std;

class complex
{
public:
complex(double real=0.0,double imag = 0.0);
complex operator +(complex c2);
complex operator -(complex c2);
complex operator *(complex c2);
complex operator /(complex c2);
bool IsZero();
void Display();
private:
double real;
double imag;
};

complex::complex(double real,double imag)
{
this->real = real;
this->imag = imag;
}

complex complex::operator +(complex c2)
{
return complex(real + c2.real,imag + c2.imag);
}

complex complex::operator -(complex c2)
{
return complex(real - c2.real,imag - c2.imag);
}

complex complex::operator *(complex c2)
{
return complex((real * c2.real - imag * c2.imag),(real * c2.imag + imag * c2.real));
}

complex complex::operator /(complex c2)
{
double x, y;
x = (real * c2.real + imag * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag);
y = (-real * c2.imag + imag * c2.real)/(c2.real * c2.real + c2.imag * c2.imag);
return complex(x,y);
}

bool complex::IsZero()
{
if(real == 0 && imag == 0)
{
return true;
}else{
return false;
}
}

void complex::Display()
{
if(imag<0)
{
cout< }else{
cout< }
}

int main()
{

complex c1(5,4),c2(0,0),c3;
cout<<"相加:";
c3 = c1 + c2;
c3.Display();

cout<<"相减:";
c3 = c1 - c2;
c3.Display();

cout<<"相乘:";
c3 = c1 * c2;
c3.Display();

cout<<"相除:";
if(c2.IsZero())
{
cout<<"除数不能为零"< }
else{

c3 = c1 / c2;
c3.Display();
}
return 1;
}

3、

#include
#include
#include
#include

#define OK 1
#define ERROR 0
using namespace std;

typedef int Status; /*返回值的类型*/

static int STU_COUNT=0;

struct student
{
long num;
char name[20];
float cpp;
float english;
float math;
float avg;
}stu[100];

Status Menu()
{
int k=-1;
while(k<0||k>4){
system("cls");
cout<<" ";
cout<<"|-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-|\n "
"| c++语言学生信息管理程序实现 |\n "
"| 1、全班成绩输入 |\n "
"| 2、求出每一个同学的平均成绩 |\n "
"| 3、按平均成绩的升序排序 |\n "
"| 4、输出全班成绩表 |\n "
"| 0、系统推出 |\n "
"|-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-|\n\n\n";
fflush(stdin);
if(k==-1)
{
cout<<" "<<"请选择功能:";
}else if(k<0 || k>4)
{
cout<<" "<<"(选择错误)请重新选择:";
}
scanf("%d",&k);

}
return k;
}
Status DisColum()
{
cout<cout<<<<<<<return OK;
}

Status ReadScore()
{
cout<<" 你要输入多少同学的成绩记录:";
cin>>STU_COUNT;

//DisColum();
for(int i=0; i{

cout<<" 第"<cout<<" ";
cin>>stu[i].num>>stu[i].name>>stu[i].cpp>>stu[i].english>>stu[i].math;
}
return OK;
}

Status CalAvgScore()
{
if(STU_COUNT==0)
{
cout<<" 没有学生记录信息...";
return ERROR;
}
for(int i=0; i{
stu[i].avg = (stu[i].cpp + stu[i].english + stu[i].math)/3.0;
}
return OK;
}

Status SortByAvg()
{
if(STU_COUNT==0)
{
cout<<" 没有学生记录信息...";
return ERROR;
}
char str[20];
for(int i=0; i{
for(int j=0; j{
if(stu[j+1].avg{
swap(stu[j].num,stu[j+1].num);
strcpy(str,stu[j].name);
strcpy(stu[j].name,stu[j+1].name);
strcpy(stu[j+1].name,str);
swap(stu[j].cpp,stu[j+1].cpp);
swap(stu[j].english,stu[j+1].english);
swap(stu[j].math,stu[j+1].math);
swap(stu[j].avg,stu[j+1].avg);
}
}
}
cout<<"排序完成....";
return OK;
}

Status Display()
{
if(STU_COUNT==0)
{
cout<<" 没有学生记录信息...";
return ERROR;
}
else{
DisColum();
for(int i=0; i{
cout<<" ";
cout<<<<<<<}
return OK;
}
}

Status Operation()
{
int k=-1;

do{
switch(k=Menu())
{
case 0:
exit(1);
break;
case 1:
ReadScore();
cout<<" 录入完成....";
break;
case 2:
if(CalAvgScore())
cout<<" 平均值计算完成....";
getch();
break;
case 3:
SortByAvg();
getch();
break;
case 4:
CalAvgScore();
Display();
getch();
break;
default:
cout<<" 功能选择错误....";
getch();
break;
}
}while(k!=8);
return OK;
}

int main()
{
Operation();
return OK;
}

回答2:

没时间啊!

回答3:

我也没时间,帮你写一个:
==========================
#include
void main()
{
for(int i=1;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
{
if(i!=j&&i!=k&&j!=k)
{
if(i+j+k==6)
{
if(i==1&&j==2&&k==3)
cout<<"Red,Blue,Green"< if(i==1&&j==3&&k==2)
cout<<"Red,Green,Blue"< if(i==2&&j==1&&k==3)
cout<<"Blue,Red,Green"< if(i==2&&j==3&&k==1)
cout<<"Blue,Green,Red"< if(i==3&&j==1&&k==2)
cout<<"Green,Red,Blue"< if(i==3&&j==2&&k==1)
cout<<"Green,Blue,Red"< }
}
}
}
===========================