OC学生成绩管理类(三 Student学生类)

本文介绍了一个简单的学生成绩管理系统的设计与实现,系统采用Objective-C语言,通过Student类和Score类来管理学生的个人信息及成绩,包括数学、历史和英语等科目的分数,并提供了输出学生完整信息的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Student.h文件

//
//  Student.h
//  练习 类 学生成绩管理
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Score.h"
@interface Student : NSObject
{
    // 特征
    NSString *_stuName;
    NSString *_stuId;
    NSString *_stuSex;
    Score *_score;
}

// 自定义的初始化方法
- (id)initWithName:(NSString *)stuName
             stuId:(NSString *)stuId
               sex:(NSString *)sex
         mathSocre:(CGFloat)mathScore
      historyScore:(CGFloat)historyScore
      englishScore:(CGFloat)englishScore;
// 自定义的初始化方法2
- (id)initWithName:(NSString *)stuName
             stuId:(NSString *)stuId
               sex:(NSString *)sex
             score:(Score *)score;
// 输出当前学生的所有信息
- (void)printInfo;


// 设置器和访问器
// name
- (void)setName:(NSString *)name;
- (NSString *)name;
// stuId
- (void)setStuId:(NSString *)stuId;
- (NSString *)stuId;
// sex
- (void)setSex:(NSString *)sex;
- (NSString *)sex;
// score
- (void)setScore:(Score *)score;
- (Score *)score;
@end

Student.m文件

//
//  Student.m
//  练习 类 学生成绩管理
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "Student.h"

@implementation Student
// 自定义初始化方法
- (id)initWithName:(NSString *)stuName
             stuId:(NSString *)stuId
               sex:(NSString *)sex
         mathSocre:(CGFloat)mathScore
      historyScore:(CGFloat)historyScore
      englishScore:(CGFloat)englishScore{
    
    self = [super init];
    if(self){
        _stuName = stuName;
        _stuId = stuId;
        _stuSex = sex;
        // 创建Score类的对象
        Score *score = [[Score alloc] initWithId:stuId englishScore:englishScore historyScore:historyScore mathScore:mathScore];
        _score = score;
    }
    return self;
}

- (id)initWithName:(NSString *)stuName
             stuId:(NSString *)stuId
               sex:(NSString *)sex
             score:(Score *)score{
    self = [super init];
    if(self){
        _stuName = stuName;
        _stuId = stuId;
        _stuSex = sex;
        _score = score;
    }
    return self;
}
// 设置器和访问器
// name
- (void)setName:(NSString *)name{
    _stuName = name;
}
- (NSString *)name{
    return _stuName;
}
// stuId
- (void)setStuId:(NSString *)stuId{
    _stuId = stuId;
}
- (NSString *)stuId{
    return _stuId;
}
// sex
- (void)setSex:(NSString *)sex{
    _stuSex = sex;
}
- (NSString *)sex{
    return _stuSex;
}
// score
- (void)setScore:(Score *)score{
    _score = score;
}
- (Score *)score{
    return _score;
}

// 输出当前学生的所有信息
- (void)printInfo{
    NSLog(@" %@ %@ %@ Math:%0.2f History:%0.2f English:%0.2f Ave:%0.2f Total:%0.2f",
          _stuName,
          _stuId,
          _stuSex,
          [_score mathScore],
          [_score historyScore],
          [_score englishScore],
          [_score averageScore],
          [_score totalScore]);
    
}
@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值