This is from the Object oriented programming book Chapter 12. Please only use th
ID: 3556142 • Letter: T
Question
This is from the Object oriented programming book Chapter 12. Please only use things from chapters 1-12. Points are awarded promptly. Write in C++ only please
Complete the following tasks:
a. Create a class named teacher that holds a Teacher's first and last names and the grade level the teacher teaches. Include a constructor function that uses default first and last names such as "ZZZZZZZZZ" and a defaut grade level such as 0, when no arguements are provided.
b. Create a class named Student that hold's a Student's first and last names. Include a constructor function thatt uses default first and last names, such as "ZZZZZZZ", when no student names are provided.
c.Create a class named Classroom. A Classroom holds a Teacher and an array of 35 Student objects.
d. Create a class named School. A School contains an array of 100 Classroom objects. (This class is being designed to be a very large class, to more quickly demonstrate running out of memory.)
e. In a main() demonstration function, declare a pointer to an array of 500 School objects and include code to handle any memory allocation errors that occur. In a loop, declare 500 array objects at a time, continue to rewrite the main() function if necessary until you create enough School objects to cause a memory allocation exception. (Hint: You might want to display a count periodically to assure yourself that the School objects are being created.) When the memory is exhausted, display an appropriate message and terminate the application. Save as MySchool.cpp
My record speaks for itself I will award the points as soon as the answer is submitted. I am offering the maxium amount of points Chegg will allow. Any help would be apperciated!
Explanation / Answer
#include<iostream>
using namespace std;
class Teacher
{
private:
string first;
string last;
int level;
public:
Teacher()
{
first="zzzz";
last="zzzz";
level=0;
}
};
class Student
{
private:
string first;
string last;
public:
Student()
{
first="zzzz";
last="zzzz";
}
};
class ClassRoom
{
private:
Teacher T;
Student S[35];
};
class School
{
private:
ClassRoom C[100];
};
int main()
{
School * S;
int i=0;
try
{
while(true)
{
S = new School[i];
cout<<i<<" schools have been created"<<endl;
i++;
}
}
catch(bad_alloc &ex)
{
cout<<"Error: "<<ex.what()<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.