- /*
- 定义一个学生,学生有学号 姓名 还有 C语言分数 和JAVA语言分数 总分 平均分
- */
- #import <Foundation/Foundation.h>
- @interface Student : NSObject
- {
-
- char *_name;
- int _cScort;
- int _javaScort;
- int _conuntScort;
- int _avgScort;
- }
- - (void)setName:(char *)name;
- - (void)setCScort:(int)cScort;
- - (void)setJavaScort:(int)javaScort;
- - (char *)name;
- - (int)cScort;
- - (int)javaScort;
- - (int)conuntScort;
- - (int)avgScort;
- - (void)printInfo;
- @end
- @implementation Student
- - (void)setName:(char *)name
- {
- _name = name;
- }
- - (void)setCScort:(int)cScort
- {
- _cScort = cScort;
- _conuntScort = _cScort + _javaScort;
- _avgScort = _conuntScort / 2;
- }
- - (void)setJavaScort:(int)javaScort
- {
- _javaScort = javaScort;
- _conuntScort = _cScort + _javaScort;
- _avgScort = _conuntScort / 2;
- }
- - (char *)name
- {
- return _name;
- }
- - (int)cScort
- {
- return _cScort;
- }
- - (int)javaScort
- {
- return _javaScort;
- }
- - (int)conuntScort
- {
- return _conuntScort;
- }
- - (int)avgScort
- {
- return _avgScort;
- }
- - (void)printInfo
- {
- NSLog(@"学生是%s",_name);
- }
- @end
- int main()
- {
- Student *s = [Student new];
- [s setCScort:90];
- [s setJavaScort:90];
- [s setName:"dd"];//这边使用中文为什么不行?????
- NSLog(@"%s的总分是=%d,平均=%d",[s name],[s conuntScort],[s avgScort]);
- return 0;
- }
复制代码
为啥 [s setName:"dd"];//这边使用中文为什么不行????? 使用英文就可以!!!?@!?@!@! |
|