//
// XViewController.m
// Function2
//
// Created by keovessna vong on 6/2/2012.
// Copyright (c) 2012 Burapha. All rights reserved.
//
#import "XViewController.h"
@implementation XViewController
@synthesize textA;
@synthesize textB;
@synthesize textC;
@synthesize labelX1;
@synthesize labelX2;
-(IBAction)cal:(id)sender
{
NSString *strA = [[NSString alloc]initWithString:[self.textA text]] ;
NSString *strB = [[NSString alloc]initWithString:[self.textB text]] ;
NSString *strC = [[NSString alloc]initWithString:[self.textC text]] ;
int a,b,c ;
a = [strA integerValue] ;
b = [strB integerValue] ;
c = [strC integerValue] ;
float x1,x2;
float Data = b*b - 4.0*a*c;
if(Data<0){
self.labelX1.text = @"NULL";
self.labelX2.text = @"NULL";
}else{
x1 = (-b-pow(Data,0.5))/2/a;
x2 = (-b+pow(Data,0.5))/2/a;
self.labelX1.text = [NSString stringWithFormat:@"%f", x1] ;
self.labelX2.text = [NSString stringWithFormat:@"%f", x2] ;
}
}
-(IBAction)clear:(id)sender
{
self.labelX1.text= @"";
self.labelX2.text= @"";
self.textA.text=@"";
self.textB.text=@"";
self.textC.text=@"";
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder]; // hide keyboard with return
return true ;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
NSLog(@"view did load");
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
|
No comments:
Post a Comment