如何在C++下美化DOS程序界面

如何在C++下美化DOS程序界面,第1张

这是我写的一个小程序,感觉界面还可以,把代码发给你研究下吧。

#include <iostreamh>

#include <stdlibh>

#include <stdioh>

/

Program Function: Implement the functions of a complex class

Author: Chu Shanming

Date: Nov 20th,2009

CopyRight 2008-2009 All Rights Reserved

Version:100

Bugs: Unknown

/

class Complex{

private:

float real,image;

public:

Complex(float r = 0,float i = 0):real(r),image(i){}

//~Complex();

Complex(const Complex& s){

real = sreal;

image = simage;

}

friend Complex operator + (Complex& a,Complex& b);

friend Complex operator - (Complex& a,Complex& b);

friend Complex operator (Complex& a,Complex& b);

friend Complex operator / (Complex& a,Complex& b);

friend Complex& operator += (Complex& a,Complex& b);

friend Complex& operator -= (Complex& a,Complex& b);

friend bool operator == (Complex& a,Complex& b);

friend bool operator != (Complex& a,Complex& b);

friend Complex& operator ++ (Complex& a);

friend Complex& operator -- (Complex& a);

friend Complex operator ++ (Complex& a,int);

friend Complex operator -- (Complex& a,int);

friend ostream& operator << (ostream& out, Complex& a);

};

ostream& operator << (ostream& out, Complex& a){

if(areal != 0)

out<<areal;

if(aimage > 0){

out<<'+';

out<<aimage;

out<<'i';

}

if(aimage < 0){

out<<'-';

out<<-aimage;

out<<'i';

}

if(aimage == 0 && areal == 0)

out<<0;

return out;

}

Complex operator + (Complex& a,Complex& b){

Complex temp;

tempreal = areal + breal;

tempimage = aimage + bimage;

return temp;

}

Complex operator - (Complex& a,Complex& b){

Complex temp;

tempreal = areal - breal;

tempimage = aimage - bimage;

return temp;

}

Complex operator (Complex& a,Complex& b){

Complex temp;

tempreal = areal breal - aimage bimage;

tempimage = aimage breal + areal bimage;

return temp;

}

Complex operator / (Complex& a,Complex& b){

if(breal == 0 && bimage == 0){

cout<<"零做除数!"<<endl;

exit(0);

}

Complex temp;

float t = breal breal - bimage bimage;

tempreal = (areal breal + aimage bimage)/t;

tempimage = (aimage breal - areal bimage)/t;

return temp;

}

Complex& operator += (Complex& a,Complex& b){

areal = areal + breal;

aimage = aimage + bimage;

return a;

}

Complex& operator -= (Complex& a,Complex& b){

areal = areal - breal;

aimage = aimage - bimage;

return a;

}

bool operator == (Complex& a,Complex& b){

if(areal == breal && aimage == bimage)

return true;

else

return false;

}

bool operator != (Complex& a,Complex& b){

if(areal == breal && aimage == bimage)

return false;

else

return true;

}

Complex& operator ++ (Complex& a){

areal++;

return a;

}

Complex& operator -- (Complex& a){

areal--;

return a;

}

Complex operator ++ (Complex& a,int){

Complex temp = a;

areal++;

return temp;

}

Complex operator -- (Complex& a,int){

Complex temp = a;

areal--;

return temp;

}

void init(){

printf("\n");

printf(" Welcome to the World of Complex!\n");

printf("Program Function: Implement the functions of a complex class\n");

printf("Author: Chu Shanming\n");

printf("Date: Nov 20th,2009\n");

printf("CopyRight 2008-2009 All Rights Reserved\n");

printf("Version:100\n");

printf("Bugs: Unknown\n\n");

printf("\n");

}

void function(){

printf("\n请选择运算:\n");

printf("1 a+b\t\t2 a-b\t\t3 ab\t\t4 a/b\n");

printf("5 a+=b\t\t6 a-=b\t\t7 a==b\t\t8 a!=b\n");

printf("9 a++\t\t10 a--\t\t11 ++a\t\t12 --a\n");

printf("选择序号:");

}

void main(){

init();

float r1,r2,i1,i2;

cout<<"请输入第一个复数的实部:";

cin>>r1;

cout<<"请输入第一个复数的虚部:";

cin>>i1;

cout<<"请输入第二个复数的实部:";

cin>>r2;

cout<<"请输入第二个复数的虚部:";

cin>>i2;

Complex a(r1,i1);

Complex b(r2,i2);

r1: system("cls");

init();

cout<<"\n"<<"复数a: "<<a<<"\t\t"<<"复数b: "<<b<<endl;

function();

int j;

cin>>j;

cout<<"\n结果:"<<endl;

switch(j){

case 1:

cout<<a + b<<endl;

break;

case 2:

cout<<a - b<<endl;

break;

case 3:

cout<<a b<<endl;

break;

case 4:

cout<<a / b<<endl;

break;

case 5:

cout<<(a += b)<<endl;

break;

case 6:

cout<<(a -= b)<<endl;

break;

case 7:

if(a == b)

cout<<"True"<<endl;

else

cout<<"False"<<endl;

break;

case 8:

if(a == b)

cout<<"False"<<endl;

else

cout<<"True"<<endl;

break;

case 9:

cout<<a++<<endl;

break;

case 10:

cout<<a --<<endl;

break;

case 11:

cout<<++a <<endl;

break;

case 12:

cout<<--a<<endl;

break;

default:

goto r1;

}

getchar();

goto r1;

}

楼主,应该学习visual basic 或者 delphi 7,这两个软件是针对对象编程的。(也就是按照你说的那样,点击按钮就运行。)或者你使用visual studio 2010这类软件编程,建立窗口应用程序,实现面向对象的程序设计。不过,在这之前,楼主得下功夫学习上面的软件的使用哦。

C语言并不是所有的都是DOS那些的窗口程序,但是你首先要会编写DOS类的窗口类程序

现在先教你DOS类的美化

首先教你改背景和字体颜色 :

颜色属性由两个十六进制数字指定 -- 第一个为背景,第二个则为

前景。每个数字可以为以下任何值之一:

0 = 黑色 8 = 灰色

1 = 蓝色 9 = 淡蓝色

2 = 绿色 A = 淡绿色

3 = 浅绿色 B = 淡浅绿色

4 = 红色 C = 淡红色

5 = 紫色 D = 淡紫色

6 = ** E = 淡**

7 = 白色 F = 亮白色

例如: "COLOR fc" 在亮白色上产生亮红色

这些是DOS的指令,你可以使用

system("color fc");

来完成美化

如果是system("title C程序");的话,那标题就变成了C程序

以上就是关于如何在C++下美化DOS程序界面全部的内容,包括:如何在C++下美化DOS程序界面、学习C++后,程序运行都是一个黑黑的窗口 怎么才能在一个自己美化后的界面运行要学习什么、c语言编写的都是类dos窗口程序吗,如何美化一下 啊等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9409805.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存