#include <iostream>
#include <vector>
#include <string>
using namespace std;
class SinhVien
{
protected:
int maSV;
string hoTen;
string diaChi;
int tongsoTC;
float diemTB;
public:
SinhVien(int, string, string, int, float);
void printfSV();
int masoSV() { return maSV; }
string hoTenn() { return hoTen; }
string diaChii() { return diaChi; }
int ttongsoTC() { return tongsoTC; }
float ddiemTB() { return diemTB; }
};
SinhVien::SinhVien(int maSV, string hoTen, string diaChi, int tongsoTC, float diemTB)
{
this->maSV = maSV;
this->hoTen = hoTen;
this->diaChi = diaChi;
this->tongsoTC = tongsoTC;
this->diemTB = diemTB;
}
void SinhVien::printfSV()
{
cout << "[" << maSV << ", " << hoTen << ", " << diaChi << ", " << tongsoTC << ", " << diemTB << "]";
cout << "\n";
}
class SVVB2 : public SinhVien
{
private:
float diemTN;
public:
SVVB2(int maSV, string hoTen, string diaChi, int tongsoTC, float diemTB, float diemTN) : SinhVien(maSV, hoTen, diaChi, tongsoTC, diemTB), diemTN(diemTN)
{
}
};
class SVHDH : public SinhVien
{
private:
string tenLV;
float diemLV;
public:
SVHDH(int maSV, string hoTen, string diaChi, int tongsoTC, float diemTB, string tenLV, float diemLV) : SinhVien(maSV, hoTen, diaChi, tongsoTC, diemTB), tenLV(tenLV), diemLV(diemLV)
{
}
};
class TruongDaiHoc
{
private:
string tenTruong;
vector<SinhVien *> sv;
int soSV;
public:
TruongDaiHoc(string);
~TruongDaiHoc();
void initDsSv();
void printfDsSv();
void xetTN();
};
TruongDaiHoc::TruongDaiHoc(string tenTruong)
{
this->tenTruong = tenTruong;
this->soSV = 0;
}
TruongDaiHoc::~TruongDaiHoc()
{
for (int i = 0; i < sv.size(); ++i)
{
delete sv[i];
}
}
void TruongDaiHoc::initDsSv()
{
sv.push_back(new SVVB2(2301, "Nguyen Van Minh", "HCM", 90, 8.0, 7.8));
sv.push_back(new SVVB2(2305, "Tran Thi Thu", "NamDinh", 95, 8.5, 8.7));
sv.push_back(new SVVB2(2334, "Pham Quoc Cuong", "PhuYen", 86, 4.9, 5.2));
sv.push_back(new SVVB2(2376, "Ngo Ba Vinh", "QuangNgai", 82, 6.3, 5.9));
sv.push_back(new SVVB2(2342, "Ma Tuan Phong", "HaNoi", 92, 8.2, 8.5));
sv.push_back(new SVHDH(1826, "Cao Van Kien", "NinhThuan", 135, 7.3, "Gialapmang", 7.0));
sv.push_back(new SVHDH(1832, "Nguyen Thi Tra", "HoaBinh", 127, 8.4, "Vuonxanh", 8.2));
sv.push_back(new SVHDH(1759, "Tu Van Khang", "ThaiNguyen", 112, 4.9, "Traingot", 5.2));
sv.push_back(new SVHDH(1778, "Pham Ninh Duong", "KienGiang", 128, 6.3, "Xulyrac", 7.5));
sv.push_back(new SVHDH(1895, "Bui Tuan Huy", "Hue", 122, 7.2, "Thietkenha", 7.0));
soSV = 10;
}
void TruongDaiHoc::printfDsSv()
{
for (int i = 0; i < soSV; i++)
{
sv[i]->printfSV();
}
cout << "\n";
}
void TruongDaiHoc::xetTN()
{
for (int i = 0; i < soSV; i++)
{
if (sv[i]->ttongsoTC() >= 84 && sv[i]->ddiemTB() >= 5.0 && sv[i]->ddiemTB() >= 5.0)
{
cout << "Sinh vien co ma: " << sv[i]->masoSV() << " du dieu kien tot nghiep." << endl;
}
else
{
cout << "Sinh vien co ma: " << sv[i]->masoSV() << " khong du dieu kien tot nghiep." << endl;
}
}
}
int main()
{
TruongDaiHoc dh("DHCongNgheThongTin");
dh.initDsSv();
dh.printfDsSv();
dh.xetTN();
return 0;
}
Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!
OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter name:";
getline (cin, name);
cout << "Hello " << name;
return 0;
}
C++ is a widely used middle-level programming language.
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
//code
}
else {
//code
}
You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to If-Else-If ladder.
switch(conditional-expression){
case value1:
// code
break; // optional
case value2:
// code
break; // optional
......
default:
code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
// code
}