下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
//// main.m// Calcultor/* 计算器的简单实现 1.加法 2.减法 3.乘法 4.除法 实现两个数的运算 */#import <Foundation/Foundation.h>#import "Calcultor.h"#import "Menu.h"int main(int argc,const char * argv[]){ Calcultor * cal = [[Calcultor alloc]init]; //[cal setNumber1:10]; //[cal setNumber2:10]; //[cal setResult:0]; //[cal setCalcultorOperator:'+']; // [cal initWithNumber1:10 andInitWithNumber2:10 andInitWithCalcultorOperator:'+']; //[cal counter]; //NSLog(@"%@",cal); double number1; double number2; // double result; char operator; NSLog(@"请输入一个算式例如A+B:\n"); scanf("%lf",&number1); scanf("%c",&operator); scanf("%lf",&number2); [cal setNumber1:number1]; [cal setNumber2:number2]; //[cal setCalcultorOperator:operator]; // [cal counter:operator]; NSLog(@"您计算的结果是=%.lf",[cal counter:operator]); // // Menu * menu = [[Menu alloc]init];// // [menu showMenu]; return 0;}@H_301_6@#import <Foundation/Foundation.h>#import "Calcultor.h"@interface Menu : NSObject{ Calcultor * _cal;}/**显示菜单选项*/-(voID)showMenu:(Calcultor *)cal;@end@H_301_6@#import "Menu.h"@implementation Menu/**显示菜单选项*/-(voID)showMenu:(Calcultor *)cal;{ // NSLog(@"菜单");// NSLog(@"1.计算 + - * /");// NSLog(@"2.计算一个数的平方");// NSLog(@"请输入您的的选项:");// int selectNumber;// scanf("%d",&selectNumber);// switch () {// case :// break;// // default:// break;// }}@end@H_301_6@#import <Foundation/Foundation.h>@interface Calcultor : NSObject{ @public /**用来记录 *** 作数1*/ double _number1; /**用来记录 *** 作数2*/ double _number2; /**用来记录结果*/ double _result; /**用来记录 *** 作符*/ char _calcultorOperator;}//@property声明@property double number1;@property double number2;@property double result;@property char calcultorOperator;/**加法*/-(double)add;/**减法*/-(double)subtract;/**乘法*/-(double)multiply;/**除法*/-(double)divIDe;-(double)square;/**计算器的简单实现*/-(double)counter:(char)calcultor;//-(voID)initWithNumber1:(double)number1 andInitWithNumber2:(double)number2 andInitWithCalcultorOperator:(char)calcultor;@end@H_301_6@#import "Calcultor.h"@implementation Calcultor-(ID)init{ if(self = [super init]) { _result = 0.0; } return self;}/**加法*/- (double)add{ return (_number1 + _number2); //NSLog(@"%.1lf",_result);}/**减法*/- (double)subtract{ return _number1 - _number2; //NSLog(@"%.1lf",_result);}/**乘法*/- (double)multiply{ return _number1 * _number2; //NSLog(@"%.1lf",_result);}/**除法*/- (double)divIDe{ return _number1 / _number2; //NSLog(@"%.1lf",_result);}-(double)square{ return _number1 * _number1;}/**计算器的简单实现*/-(double)counter:(char)calcultor{ //char calcultor;//局部变量 switch (calcultor) { case '+': _result = [self add]; break; case '-': _result = [self subtract]; break; case '*': _result = [self multiply]; break; case '/': _result = [self divIDe]; break; default: break; } return _result;}//- (voID)initWithNumber1:(double)number1 andInitWithNumber2:(double)number2 andInitWithCalcultorOperator:(char)calcultor//{// _number1 = number1;// _number2 = number2;// _calcultorOperator = calcultor;//}/**!!!调试用的!!!*/-(Nsstring *)description{ return [Nsstring stringWithFormat:@" *** 作数1:%.1lf *** 作数2:%.1lf 结果 : %.1lf *** 作符 : %c",_number1,_number2,_result,_calcultorOperator];}@end@H_301_6@
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的IOS计算器的实现全部内容,希望文章能够帮你解决IOS计算器的实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)