QuestionQuestion

Kindergarten
Define a struct called Child with components name, age, and toysCost.
Define a class called Kindergarten that has private members name, cost, numberOfChildren, *p a pointer of type Child, claculateCost( ). The class has the public members set( ), get( ), getCost( ), print( ), and a default parametrized constructor.
Implement all member functions of the class and implement the concept of information hiding.
Use the following driver:
int main()
{
Kindergarten KG;
KG.set("Al-Baraem", 3);
KG.print();

return 0;
}
Contents of the Child.txt file:
Ali Omar, 4 150
Hussein Ahmed, 3 177
Amal Abass, 7 312
Ibrahem Adnan, 6 358
Fatima Ali, 5 489

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include "Kindergarten.h"

#include <iostream>
#include <fstream>
using namespace std;

Kindergarten::Kindergarten() {
    name = "";
    cost = 0;
    numberOfChildren = 0;
    p = 0;
}

Kindergarten::~Kindergarten() {
    if (p != 0) {
       delete[] p;
    }
}

int Kindergarten::claculateCost() {
    int sum = 0.0;
    for (int i = 0; i < numberOfChildren; i++) {
       sum += p[i].toyCost;
    }
    return sum;
}

string Kindergarten::get() {
    return name;
}

int Kindergarten::getCost() {
    return claculateCost();
}

void Kindergarten::print() {
    cout << name << " Kindergarten has " << numberOfChildren
            << " with toys worth " << claculateCost() << " dirham\n";
}

void Kindergarten::set(string name, int numberOfChildren) {
    this->name = name;
    this->numberOfChildren = 0;
    if (p != 0) {
       delete [] p;
    }
    string fName;
    string lName;
    int age;
    int toyCost;

    fstream in;
    in.open("Child.txt", ios::in...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$15.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats