C++编程(急)!

作者&投稿:浑万 (若有异议请与网页底部的电邮联系)
可以根据以下的程序做更改:

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
int number1,number2,answer,val;
class oopcalc {
public:
void calcadd();
void calcsub();
void calcdiv();
void calcmult();
void calcfartocel();
void calcceltofar();
void calcsroot();
void exitprog();
void menu();
void badinput();
private:
int add(int x, int y);
int sub(int x, int y);
int div(int x, int y);
int mult(int x, int y);
int fartocel(int x);
int celtofar(int x);
int sqroot(int x);
};
void oopcalc::calcadd()
{
cout << "The Add Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = add(number1,number2);
cout << number1 << " + " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcsub()
{
cout << "The Subtract Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = sub(number1,number2);
cout << number1 << " - " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcdiv()
{
cout << "The Divide Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = div(number1,number2);
cout << number1 << " / " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcmult()
{
cout << "The Multiply Function\n";
cout << "First number: ";
cin >> number1;
cout << "Second number: ";
cin >> number2;
answer = mult(number1,number2);
cout << number1 << " x " << number2 << " = " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcfartocel()
{
cout << "The Farenheit to Celsius Function\n";
cout << "Enter a tempature in Farenheit: ";
cin >> number1;
answer = fartocel(number1);
cout << "The tempature in Celsius is " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcceltofar()
{
cout << "The Celsius to Farenheit Function\n";
cout << "Enter a tempature in Celsius: ";
cin >> number1;
answer = celtofar(number1);
cout << "The tempature in Farenheit is " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::calcsroot()
{
cout << "The Square Root Function\n";
cout << "First number: ";
cin >> number1;
answer = sqroot(number1);
cout << "The square root of " << number1 << " is " << answer << endl;
cout << "Press any key to continue\n";
getch();
menu();
}
void oopcalc::exitprog()
{
exit(-1);
}
void oopcalc::menu()
{
char input;
oopcalc a;
system("cls"); //执行系统命令:cls-清屏
cout << "==================MENU===============\n";
cout << "1: Add two numbers\n";
cout << "2: Subtract two numbers\n";
cout << "3: Divide two numbers\n";
cout << "4: Multiply two numbers\n";
cout << "5: Convert Farenheit to Celsius\n";
cout << "6: Convert Celsius to Farenheit\n";
cout << "7: Find the square root of a number\n";
cout << "8: Exit this program\n";
cout << "Choice: ";
cin >> input;
cout << "=====================================\n";
switch (input)
{
case '1': a.calcadd();
break;
case '2': a.calcsub();
break;
case '3': a.calcdiv();
break;
case '4': a.calcmult();
break;
case '5': a.calcfartocel();
break;
case '6': a.calcceltofar();
break;
case '7': a.calcsroot();
break;
case '8': a.exitprog();
break;
default: a.badinput();
}
}
void oopcalc::badinput()
{
cout << "BAD INPUT!\n";
cout << "Press any key to continue\n";
getch();
menu();
}
int oopcalc::add(int x, int y)
{
val = x + y;
return val;
}
int oopcalc::sub(int x, int y)
{
val = x - y;
return val;
}
int oopcalc::div(int x, int y)
{
val = x / y;
return val;
}
int oopcalc::mult(int x, int y)
{
val = x * y;
return val;
}
int oopcalc::fartocel(int x)
{
int cel = ((x - 32) * 5) / 9;
return cel;
}
int oopcalc::celtofar(int x)
{
int f;
f = x * 9 / 5 + 32;
return f;
}
int oopcalc::sqroot(int x)
{
int g = sqrt(x);
return g;
}
void main()
{
oopcalc s;
s.menu();
}

用c++编程~

这个就是大数的加法来完成
1、线算0~9这10个数的21次方是多少,存入一个数组中
因为是大数,所以可以用二维字符数组来存储
2、做一个大数的加法
void jia(char *a,char *b,char *c)
c字符串来返回ab相加的结果
3、可以写主程序了
其实就是一个循环,用字符串的一些系统函数就可以搞定

效率不知道,你试试吧

#include #define MAXLONE_STR 100#define MAXLONE_DIG 50int getDigits(char a[],int target[]){ int i=0,k=0,index_dig=0; const int two_dig=2; while (a[i]!='\0') { if(k==2){ target[index_dig++]=(a[i-1]-48)+((a[i-2]-48)*10); k=0; } else{ i++; k++; } } //当k=1时说明尾部仅有一个数字 if(k==1) target[index_dig++]=(a[i-1]-48); return index_dig; // 返回数组长度}void main(){ char test[MAXLONE_STR]="1234567";int dig[MAXLONE_DIG];int len=getDigits(test,dig);// 输出得到的数字for (int i=0;i<len;i++) printf("%d ",dig[i]);printf("
"); }

C语言编程题2道!急!!!
答:1:include<stdio.h> int main(){ int a[10];int i;int max = 0;int min = 100;int maxi=0;int mini =0;for(i=0;i<10;i++){ scanf("%d",&a[i]);if(a[i]<min){ min = a[i];mini = i;} if(a[i]>max){ max = a[i];maxi = i;} } int sum =0;for(i=0...

编程问题 急!!!
答:编程问题 急!!! 编写对话框应用程。完成简单计算器功能,如图所示:能够完成简单加减乘除运算,支持浮点数运算。... 编写对话框应用程。完成简单计算器功能,如图所示:能够完成简单加减乘除运算,支持浮点数运算。 展开  我来答 1个回答 #热议# 孩子之间打架 父母要不要干预?kaiyanghao123 2009-06-16 · TA...

编程代码 急 谢谢啊!!!
答:define F(a, b, c, d, x) ((a)*(x)*(x)*(x)-(b)*(x)*(x)+(c)*(x)-(d))define ROUND0(x) ((int)(x+0.4999999))double table[4] = {0,4,0,5};int tim = 0;//绘图范围600*800,先确定,x、y方向的比例和偏移,然后正式绘制图形 //tim记录调用次数 //table数组...

急!几道简单的编程的题,求助!!急
答:楼主的问题实在太多了,时间关系,恕不能解答。路过,帮楼主一个小忙。下面是我曾经答过的一个帖子,保证没有错误。程序比较简单,故注释不多,请楼主自行分析。题目:编写统计学生程序,设有十个学生成绩分别是:56 69 84 82 73 88 99 63 100 80,统计低于60分,60~69,70~79,80~89,90~99...

急!!!高难度c语言编程题,高手请进帮忙!!!
答:很简单 include<stdio.h> void main(){ int ix,iy;printf("please input the data of x:");scanf("%d",&ix);if(x<-5&&x>0)printf("the y is :%d",ix);if(x==0){ iy=ix-1;printf("the y is:%d"&iy);} if(x<0&&x<10)printf("the y is: 1");printf("input any ...

紧急求助:c语言编程!!!
答:1,解:源程序如下:main(){ int a[10],x,i,j=0;printf("enter 10 jinzhi:\n");scanf("%d",&x);printf("%d(10)=",x);while (x){ a[j++]=x%2;x=x/2;} for (i=j-1;i>=0;i--)printf("%d",a[i]);printf("(2)");} 2,解:源程序如下:main(){ int a[10],n=...

c++编程题,急!
答:public abstract class AEntity { protected float Radius { get; set; } public abstract float Area (); public abstract float Volume (); public virtual string OutPutArea () { return "面积为:" + Area().ToString(); } public virtual string OutputVolume ()...

C语言编程题目!急.明天就要用!!!
答:刚写的,代码如下:include<stdio.h> include<string.h> define N 20 struct stu { long num;char name[20];char sex;float score[7];} a[N];void input(int p){ long tmpn;char tmpc,tmps[20];float tmp;int i,j;scanf("%ld",&tmpn);a[p].num=tmpn;scanf("%c",&tmpc);j...

一道C语言编程!!急急急
答:其实你可以建一个宏,这样无论c,n怎样变化都可以,你只要修改宏就可以。上面这位仁兄,他是在main函数里输入c,n的值,这样也是可以的。你要理解,首先是要了解print_line1、print_linei、print_linen这3个函数是干什么的,有什么用。C语言是面向过程的语言,它注重函数的封装,有时候我们使用一些...

编程软件有哪些
答:一、编程软件:1、电脑编程软件主要有:BASIC、PASCAL、C、COBOL、FORTRAN、LOGO以及VC、VB java等。2、C\C++ 常用软件是MS VC++(6.0和更高版本)集成在微软的开发工具visual studio中,JAVA桌面编程常用软件是netbean,网络编程是MyEclipse(包括了常用的Eclipse和常用工具,目前Java最流行的网络编程软件...