[C/OC的那点事儿]Objective-C实现学生成绩管理系统(4)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:33 点击:次
p> }
p>
p> }
p>
p> NSLog(@"未找到学号为%d的学生.",studentID);
p>
p>
p>}
p>
p>-(void)SortStudentArray// >0升序,<0降序
p>{
p> NSLog(@"按照学号排序请输入 (id)");
p>
p> NSLog(@"按姓名排序请输入(name)");
p>
p> NSLog(@"按照年龄排序请输入(age)");
p>
p> NSLog(@"按照成绩排序(score)请输入:");
p>
p> char charKey[10] ;
p> scanf("%s",charKey);
p>
p> NSString *tempkey = [NSString stringWithUTF8String:charKey];
p> NSString *key = [tempkey lowercaseString];
p> BOOL ascending = NO;
p> NSLog(@"是否开启降序模式( 默认不开启 )?(yes or no):");
p> char ascendingStr[10] ;
p> scanf("%s",ascendingStr);
p> NSString *ascendingKey =[[NSString stringWithUTF8String:ascendingStr] lowercaseString];
p>
p> if ([ascendingKey isEqualToString:@"yes"])
p> ascending = YES;
p> else
p> ascending = NO;
p>
p>
p> if ([key isEqualToString:@"id"]) {
p>
p> NSSortDescriptor *sortByID = [NSSortDescriptor sortDescriptorWithKey:@"stuID" ascending:ascending];
p>
p> [studentArray sortUsingDescriptors:[NSArray arrayWithObject:sortByID]];
p>
p> }
p> else if([key isEqualToString:@"name"])
p> {
p> NSSortDescriptor *sortByName= [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:ascending];
p>
p> [studentArray sortUsingDescriptors:[NSArray arrayWithObject:sortByName]];
p>
p>
p> }
p> else if([ key isEqualToString:@"age"])
p> {
p> NSSortDescriptor *sortByAge = [NSSortDescriptor sortDescriptorWithKey:@"age" ascending:ascending];
p>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>