Classroom ID Classroom Name Rental Fees
CR1 Apple 50.00
CR2 Bottle 30.00
CR3 Caramel 80.00
..................................................
fyi: struct classroomType
classroomType.classrooms[20]
I wanted to write a C++ code to insert
Classroom ID: CR6
Classroom Name: Faith
Rental Fees: 75.00
What I did was:
classroomType classrooms[5] = {"CR6", "Faith", 75.00};
But I don't think that I am right. Please help. Thank you.
Last edited on
1 2 3 4 5
|
struct ClassRoom {
string id;
string name;
float rentalFee;
};
|
1 2 3 4
|
ClassRoom classrooms[20];
classrooms[5].id = "CR6";
classrooms[5].name = "Faith";
classrooms[5].rentalFee = 75.00;
|
EDIT:
A more advanced way would be to create constructor for the struct:
1 2 3 4 5 6 7 8 9 10 11
|
struct ClassRoom {
string id;
string name;
float rentalFee;
// A constructor:
ClassRoom( string _id, string _name, float _rentalFee) {
id = _id;
name = _name;
rentalFee = _rentalFee;
};
};
|
1 2 3
|
ClassRoom classrooms[20];
// calling constructor
classrooms[5] = ClassRoom ("CR6", "Faith", 75.00);
|
But I am afraid I am only making it harder for you to understand :).
Last edited on
Thank you so much for teaching me! :)