Sử dụng hàm với class trong C++
em làm bài quản lý sinh viên em dùng hai hàm:
void typeStudentMangement()
{
cout <<"type number Student: ";
cin >> nStudent;
if(nStudent <=0 )
{
cout <<"type number Student less equal 1" <<endl;
}
student arr_student[nStudent];
for (int i = 0; i < nStudent; ++i)
{
arr_student[i].setInfoStudent();
}
cout <<"" << endl;
}
void presentInforStudent()
{
student arr_student[nStudent];
for (int i = 0; i < nStudent; ++i)
{
arr_student[i].showInfoStudent();
}
}
em muốn khi gọi hàm sủ dung chung 1 class arr_student[nStudent]; giống nhau. như mà khi in ra ko lấy chung 1 class được? khi khai báo class student arr_student[nStudent]; ở public thì mọi việc điều được.
cho em hỏi khi khai báo vậy, mình muốn thiết lâp con số sinh viên trong 1 lớp học khác dữ liệu có bị thay đổi hay không ? vì arr_student[10]; khác arr_student[20]; không ? nữa em còn làm class lớp học nữa
làm sao mà gọi được class từ function khác cùng dữ liệu với một function khác?
cảm on mọi người đã đọc.
Tóm lại là bạn muốn làm gì? Mình đọc mà chẳng hiểu bạn muốn nói gì.
Mình có hai hàm mục đính dùng trong 1 class. Khi hàm thứ 2 được gọi mà ko co dữ liệu?
Khi khai báo student arr-stu[10] với khai báo class arr-stu[20] thi khac nhau k?
Bạn up code cả class được không?
void student::setSchool(char School[30])
{
sSchool = School;
}
void student::setClass(char Class[30])
{
sClass = Class;
}
void student::setMSSV(int MSSV)
{
iMSSV = MSSV;
}
string student::getSchool()
{
return sSchool;
}
string student::getnumClass()
{
return sClass;
}
int student::getMSSV()
{
return iMSSV;
}
void student::setInfoStudent()
{
// getline();
}
void student::showInfoStudent()
{
cout << "Name of Student: " << getName() << endl;
cout << "Age of Student: " << getAge()<< endl;
cout << "Address of Student: " << getAddress() << endl;
cout << "NumerPhone of Student: " << getNumPhone() << endl;
cout << "CMND of Student: " << getCMND() <<endl;
cout << "Name of School of Student: " << getSchool() <<endl;
cout << “Class of Student: " << getnumClass() <<endl;
cout << “Code of Student: " << getMSSV() <<endl;
cout <<”” << endl ;
}
#include “string”
#include “person.h”
#define comma “,”
using namespace std;
class student: public person
{
private:
string sName,name,sClass,sSchool;
char cAddress[30],cNameClasse[30],cNameSchool[30],cNumPhone[12];
string cnumClass;
int i,age,cmnd,iMSSV,mssv;
public:
int numStudent;
void setSchool(char School[30]);
void setClass(char cClass[30]);
void setMSSV(int MSSV);
void setInfoStudent();
void showInfoStudent();
};