码迷,mamicode.com
首页 > 编程语言 > 详细

对象成员数组

时间:2016-05-31 06:26:38      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

#include "stdafx.h"

#include<iostream>

#include<memory>

#include<string>

using namespace std;

class CSelsctLesson

{

public:

                CSelsctLesson();

                CSelsctLesson( string lesson ) { LessonName = lesson; }

void setLesson(string lesname);

string Getlesson() { return LessonName; }

private:

string LessonName;

};

CSelsctLesson::CSelsctLesson()

{

                LessonName = "" ;

}

void CSelsctLesson ::setLesson(string lesname)

{

                LessonName = lesname ;

}

class Student

{

int StudentID;

string name;

CSelsctLesson SelectLessonName[5];

int selectNumber;

public:

                Student( int value , string str)

                {

                                selectNumber = 0;

                                name = str ;

                                StudentID = value;

                }

void Addlesson(string lesson);

string GetLesson(int index)

                {

return SelectLessonName[index ].Getlesson();

                }

string GetStudentName() { return name; }

int GetSelectNum()

                {

return selectNumber;

                }

};

void Student ::Addlesson(string lesson)

{

if (selectNumber < 4)

                                SelectLessonName[selectNumber++].setLesson( lesson);

}

int main()

{

Student student1(1511435, "helloworld" );

                student1.Addlesson( "Computer");

                student1.Addlesson( "English");

int number = student1.GetSelectNum();

                cout << student1.GetStudentName() << "course is:";

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

                                cout << student1.GetLesson(i) << " " ;

                cout << endl;

                system( "pause");

return 0;

}

技术分享

对象成员数组

标签:

原文地址:http://www.cnblogs.com/summercloud/p/5544543.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!