iOS 簡單的計算器 個人覺得很不錯的邏輯

2021-06-19 06:23:15 字數 3598 閱讀 5036

步驟:

1.開啟xcode,單機creat a new xcode project

3.填寫專案名稱單機next

4.viewcontroller.h中定義成員和方法

#import

@inte***ce viewcontroller : uiviewcontroller

@property(retain,nonatomic)uibutton *button;

@property(retain,nonatomic)uilabel *label;

@property(retain,nonatomic)nsmutablestring *string;

@property(assign,nonatomic)double num1,num2,num3,num4;

@end

4.viewcontroller.m

#import "viewcontroller.h"

@inte***ce viewcontroller ()

@end

@implementation viewcontroller

@synthesize button,label,string,num1,num2,num3,num4;//string儲存字元,顯示數值。num1是存輸入的數值,num2是存運算子前的數值,num3是運算結果,num4是判斷進行何種運算

- (void)viewdidload

} //單獨新增0

uibutton *button0=[uibutton buttonwithtype:uibuttontyperoundedrect];

[button0 setframe:cgrectmake(30, 345, 60, 60)];

[button0 settitle:@"0" forstate:uicontrolstatenormal];

[button0 addtarget:self action:@selector(one:) forcontrolevents:uicontroleventtouchupinside];

[self.view addsubview:button0];

//新增運算子

nsarray *array1=[nsarray arraywithobjects:@"+",@"-",@"*",@"/",nil];

for (int i=0; i<4; i++)

//新增=

uibutton *button2=[uibutton buttonwithtype:uibuttontyperoundedrect];

[button2 setframe:cgrectmake(160, 410, 125, 35)];

[button2 settitle:@"=" forstate:uicontrolstatenormal];

[button2 addtarget:self action:@selector(go:) forcontrolevents:uicontroleventtouchupinside];

[self.view addsubview:button2];

//新增清除鍵

uibutton *button3=[uibutton buttonwithtype:uibuttontyperoundedrect];

[button3 setframe:cgrectmake(30, 410, 125, 35)];

[button3 settitle:@"ac" forstate:uicontrolstatenormal];

[button3 addtarget:self action:@selector(clean:) forcontrolevents:uicontroleventtouchupinside];

[self.view addsubview:button3];

//新增.

uibutton *button4=[uibutton buttonwithtype:uibuttontyperoundedrect];

[button4 setframe:cgrectmake(95, 345, 60, 60)];

[button4 settitle:@"." forstate:uicontrolstatenormal];

[button4 addtarget:self action:@selector(one:) forcontrolevents:uicontroleventtouchupinside];

[self.view addsubview:button4];

//後退

uibutton *button5=[uibutton buttonwithtype:uibuttontyperoundedrect];

[button5 setframe:cgrectmake(160, 345, 60, 60)];

[button5 settitle:@"back" forstate:uicontrolstatenormal];

[button5 addtarget:self action:@selector(back:) forcontrolevents:uicontroleventtouchupinside];

[self.view addsubview:button5];

self.string=[[nsmutablestring alloc]init];//初始化可變字串,分配記憶體

// do any additional setup after loading the view, typically from a nib.

}-(void)one:(id)sender

self.label.text=[nsstring stringwithstring:string];//顯示數值

self.num1=[self.label.text doublevalue];//儲存輸入的數值

nslog(@"%f",self.num1);

}-(void)two:(id)sender

//判斷輸入是-號

else if([self.string hasprefix:@"-"])//hasprefix:判斷字串以減號開頭

//判斷輸入是*號

else if([self.string hasprefix:@"*"])//hasprefix:判斷字串以乘號開頭

//判斷輸入是/號

else if([self.string hasprefix:@"/"])//hasprefix:判斷字串以除號開頭 }

-(void)go:(id)sender

//判斷輸入是-號

else if(self.num4==2)

//判斷輸入是*號

else if(self.num4==3)

//判斷輸入是/號

else if(self.num4==4) }

//當按下清除建時,所有資料清零

-(void)clean:(id)sender

//返回鍵

-(void)back:(id)sender

}- (void)viewdidunload

- (bool)shouldautorotatetointe***ceorientation:(uiinte***ceorientation)inte***ceorientation

@end

資料分析一些自己覺得很不錯的思路

一直覺得自己在資料分析思路和角度方面還是有存量的,能忽悠一部分人,但是今天聽了公司王博 王亞明 的思路,還是覺得很佩服。經典的市場和研發的矛盾,市場覺得研發的機型不夠不能滿足市場需求,研發覺得市場部為了賣出商品亂承諾,導致客戶不滿意,流失客戶。將商機進行聚類,層次聚類,這樣每個層級不同類個數,相當於...

簡單的計算器

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...

C 簡單的計算器

實驗目的和要求 1.設計背景 設計擁有簡單的計算功能,方便計算簡單的計算題。方便使用者的使用。2.設計功能 具有一般計算功能,能進行基本的加減乘除運算,還具有求根號,倒數等功能。特點是能進行不同進製的運算和不同進製間的轉換。3.模組分解 該計算器分為3個模組,分別是 textbox 顯示區 顯示數字...