Question

I need to get this two last parts of my project done by tonight. If you...

I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you!

Project 3 Description

In this project, use project 1 and 2 as a starting point and complete the following tasks.

Create a C++ project for a daycare. In this project, create a class called child which is defined as follows:

private members:

  • string First name
  • string Last name
  • integer Child id number
  • integer Number of weeks attended
  • string Teacher first name
  • string Teacher last name
  • integer Classroom number
  • double Balance (amount due)
  • static constant double rate and set the rate to 200.75

public members:

  • argument constructor to assign values to data members of objects.
  • default constructor to assign default values to data members of objects.
  • a void method to calculate the balance
  • a void method to print data of a child object
  • set methods for all the data members (except the rate data member)
  • get methods for all the data members.
  • create a static method called filePrint to save the data of an object to a text file. make sure to pass the object as an argument.  

in the main function:

create multiple objects (at least 3) and test the methods.

---------------------

Project 4 Description

In this project, use project 3 as a starting point and complete the following tasks.

update project 3 to include exception handling.

when the user is asked to enter the payment inside the balance method, if the user entered a negative value or a value that is grater than the current balance, you should throw an exception using the payment variable. when the exception is catches, print the amount of unaccepted payment with a message of nonacceptance.

Project 1 & 2 code:

Child.h

// Child.h

#include<iostream>

#include<string>

#include<iomanip>

using namespace std;

//Create a class Child

class Child {

       //Instance variables

private:

       //Member functions

public:

       //Constructor

       Child();

       //Pay the due amout

       void payment(double& balance, int numOfWksAttended, double weekly_charge);

       //get child details

       void print(string cFName, string cLName, int id, int weeks, string tFName, string tLName, int room, double balance);

};

Child.cpp

// Child.cpp

#include <fstream>

//Implementation of child class

#include "Child.h"

//Constructor

Child::Child() {

}

//Pay the due amout

void Child::payment(double& balance, int numOfWksAttended, double weekly_charge) {

       double paymentAmt;

       balance += numOfWksAttended * weekly_charge;

       cout << "balance :$" << balance << endl;

       cout << "\nHow much you would like to pay? : ";

       cin >> paymentAmt;

       balance -= paymentAmt;

}

//get child details

void Child::print(string cFName, string cLName, int id, int weeks, string tFName, string tLName, int room, double balance) {

       //Defines an output stream for the data file

       ofstream dataOut;

       //creating and Opening the output file

       dataOut.open("child.txt", std::ios::app);

       cout << fixed << setprecision(2);

       dataOut << fixed << setprecision(2);

       cout << "Child's First Name : " << cFName << endl;

       dataOut << "Child's First Name : " << cFName << endl;

       cout << "Child's Last Name : " << cLName << endl;

       dataOut << "Child's Last Name : " << cLName << endl;

       cout << "Child's Id Number : " << id << endl;

       dataOut << "Child's Id Number : " << id << endl;

       cout << "Number Of Wks Attended: " << weeks << endl;

       dataOut << "Number Of Wks Attended: " << weeks << endl;

       cout << "Teacher's First Name : " << tFName << endl;

       dataOut << "Teacher's First Name : " << tFName << endl;

       cout << "Teacher's Last Name : " << tLName << endl;

       dataOut << "Teacher's Last Name : " << tLName << endl;

       cout << "Class Room Number : " << room << endl;

       dataOut << "Class Room Number : " << room << endl;

       cout << "Balance Due : $" << balance << endl;

       dataOut << "Balance Due : $" << balance << endl;

       dataOut << "------------------------------------------" << endl;

       dataOut << endl;

       dataOut.close();

}

Main.cpp

// main.cpp

#include <iostream>

#include "Child.h"

using namespace std;

//Function prototypes

void getInformation(string&, string&, int&, int&, string&, string&, int&, double&);

int main()

{

       //Variable for input read

       string firstName;

       string lastName;

       int child_id;

       double balance, weekly_charge;

       int numOfWksAttended;

       string teacherfirstName;

       string teacherlastName;

       int classroomNum;

       char ch;

       //Loop until user choose n

       do {

              //Call function to get information from user

              getInformation(firstName, lastName, child_id, numOfWksAttended, teacherfirstName, teacherlastName, classroomNum, weekly_charge);

              //Set a child

              Child child;

              //Payment opt

              cout << "\nDue you want to pay balance (y/n): ";

              cin >> ch;

              ch = toupper(ch);

              while (ch != 'N' && ch != 'Y') {

                      cout << "Error!!!Incorrect oprion.Re-enter" << endl;

                      cout << "\nDue you want to make a payment (y/n): ";

                      cin >> ch;

                      ch = toupper(ch);

              }

              //Paymnet

              if (ch == 'Y') {

                      child.payment(balance, numOfWksAttended, weekly_charge);

              }

              //Child details

              cout << "\nDisplay child details: " << endl;;

              child.print(firstName, lastName, child_id, numOfWksAttended, teacherfirstName, teacherlastName, classroomNum, balance);

              //Loop continuation part

              cout << "\n Do you want to enter other child informaton(y/n): ";

              cin >> ch;

              ch = toupper(ch);

              while (ch != 'N' && ch != 'Y') {

                      cout << "Error!!!Incorrect oprion.Re-enter" << endl;

                      cout << "\n Do you want to enter other child informaton(y/n): ";

                      cin >> ch;

                      ch = toupper(ch);

              }

       } while (ch == 'Y');

       cout << "\nTerminating Application!!!" << endl;

}

//Function to get information of a child from user

void getInformation(string& fname, string& lname, int& id, int& wkNum, string& tfname, string& tlname, int& roomNum, double& weekly_charge) {

       cout << "Enter child's first name: ";

       cin >> fname;

       cout << "Enter child's last name: ";

       cin >> lname;

       cout << "Enter child's id: ";

       cin >> id;

       cout << "Enter weeks child' attended: ";

       cin >> wkNum;

       cout << "Enter teacher's first name: ";

       cin >> tfname;

       cout << "Enter teacher's last name: ";

       cin >> tlname;

       cout << "Enter class room number: ";

       cin >> roomNum;

       cout << "Enter Weekly Charge :$";

       cin >> weekly_charge;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Child.h

#include<iostream>

using namespace std;

class Child

{

private:

       string firstName, lastName;

       int child_id;

       int num_weeks_attended;

       string teacher_fname, teacher_lname;

       int classroom_num;

       double balance;

       static const double rate = 200.75;

public:

       Child();

       Child(string cFName, string cLName,int id,int weeks, string tFName, string tLName, int room);

       void calculate();

       void print();

       void setFirstName(string cFName);

       void setLastName(string cLName);

       void setNumWeeksAttended(int weeks);

       void setTeacherFirstName(string tFName);

       void setTeacherLastName(string tLName);

       void setClassroom(int room);

       void setBalance(double bal);

       void setChildID(int id);

       string getFirstName() const;

       string getLastName() const;

       int getNumWeeksAttended() const;

       string getTeacherFirstName() const;

       string getTeacherLastName() const;

       int getClassroom() const;

       double getBalance() const;

       int getChildID() const;

       static void filePrint(Child child);

};

//end of Child.h

// Child.cpp

#include "Child.h"

#include <fstream>

#include <iomanip>

Child::Child()

{

       firstName ="";

       lastName = "";

       child_id = 0;

       num_weeks_attended=0;

       teacher_fname ="";

       teacher_lname = "";

       classroom_num= 0;

       balance = 0;

}

Child::Child(string cFName, string cLName,int id,int weeks, string tFName, string tLName, int room)

{

       firstName = cFName;

       lastName = cLName;

       child_id = id;

       num_weeks_attended = weeks;

       teacher_fname = tFName;

       teacher_lname = tLName;

       classroom_num = room;

       balance = 0;

}

void Child:: calculate()

{

       double paymentAmt;

       balance += num_weeks_attended * rate;

       cout << "balance :$" << balance << endl;

       cout << "\nHow much you would like to pay? : ";

       cin >> paymentAmt;

       if(paymentAmt < 0 || paymentAmt > balance)

       {

             throw paymentAmt;

       }

       balance -= paymentAmt;

}

void Child:: print()

{

       cout << fixed << setprecision(2);

       cout << "Child's First Name : " << firstName << endl;

       cout << "Child's Last Name : " << lastName << endl;

       cout << "Child's Id Number : " << child_id << endl;

       cout << "Number Of Weeks Attended: " << num_weeks_attended << endl;

       cout << "Teacher's First Name : " << teacher_fname << endl;

       cout << "Teacher's Last Name : " << teacher_lname << endl;

       cout << "Class Room Number : " << classroom_num << endl;

       cout << "Balance Due : $" << balance << endl;

}

void Child:: setFirstName(string cFName)

{

       firstName = cFName;

}

void Child:: setLastName(string cLName)

{

       lastName = cLName;

}

void Child:: setNumWeeksAttended(int weeks)

{

       num_weeks_attended = weeks;

}

void Child:: setTeacherFirstName(string tFName)

{

       teacher_fname = tFName;

}

void Child:: setTeacherLastName(string tLName)

{

       teacher_lname = tLName;

}

void Child:: setClassroom(int room)

{

       classroom_num = room;

}

void Child:: setBalance(double bal)

{

       balance = bal;

}

void Child:: setChildID(int id)

{

       child_id = id;

}

string Child:: getFirstName() const

{

       return firstName;

}

string Child:: getLastName() const

{

       return lastName;

}

int Child:: getNumWeeksAttended() const

{

       return num_weeks_attended;

}

string Child:: getTeacherFirstName() const

{

       return teacher_fname;

}

string Child:: getTeacherLastName() const

{

       return teacher_lname;

}

int Child::getClassroom() const

{

       return classroom_num;

}

double Child:: getBalance() const

{

       return balance;

}

int Child:: getChildID() const

{

       return child_id;

}

void Child:: filePrint(Child child)

{

       //Defines an output stream for the data file

       ofstream dataOut;

       //creating and Opening the output file

       dataOut.open("child.txt", std::ios::app);

       dataOut << fixed << setprecision(2);

       dataOut << "Child's First Name : " << child.getFirstName() << endl;

       dataOut << "Child's Last Name : " << child.getLastName() << endl;

       dataOut << "Child's Id Number : " <<child.getChildID() << endl;

       dataOut << "Number Of Weeks Attended: " << child.getNumWeeksAttended() << endl;

       dataOut << "Teacher's First Name : " << child.getTeacherFirstName() << endl;

       dataOut << "Teacher's Last Name : " << child.getTeacherLastName() << endl;

       dataOut << "Class Room Number : " << child.getClassroom() << endl;

       dataOut << "Balance Due : $" << child.getBalance() << endl;

       dataOut << "------------------------------------------" << endl;

       dataOut << endl;

       dataOut.close();

}

//end of Child.cpp

// main.cpp : Driver program

#include <iostream>

#include "Child.h"

using namespace std;

//Function prototypes

void getInformation(string&, string&, int&, int&, string&, string&, int&);

int main()

{

       //Variable for input read

       string firstName;

       string lastName;

       int child_id;

       int numOfWksAttended;

       string teacherfirstName;

       string teacherlastName;

       int classroomNum;

       char ch;

       //Loop until user choose n

       do {

              //Call function to get information from user

              getInformation(firstName, lastName, child_id, numOfWksAttended, teacherfirstName, teacherlastName, classroomNum);

              //Set a child

              Child child(firstName,lastName,child_id,numOfWksAttended,teacherfirstName,teacherlastName,classroomNum);

              //Payment opt

              cout << "\nDue you want to pay balance (y/n): ";

              cin >> ch;

              ch = toupper(ch);

              while (ch != 'N' && ch != 'Y') {

                      cout << "Error!!!Incorrect oprion.Re-enter" << endl;

                      cout << "\nDue you want to make a payment (y/n): ";

                      cin >> ch;

                      ch = toupper(ch);

              }

              //Paymnet

              if (ch == 'Y') {

              try{

                      child.calculate();

              }catch(double payment)

              {

                      if(payment < 0)

                             cout<<"Amount : "<<payment<<" is negative"<<endl;

                      else

                             cout<<"Amount : "<<payment<<" greater than current balance"<<endl;

              }

              }

              //Child details

              cout << "\nDisplay child details: " << endl;;

              child.print(); // print to console

              Child::filePrint(child); // write to file

              //Loop continuation part

              cout << "\n Do you want to enter other child informaton(y/n): ";

              cin >> ch;

              ch = toupper(ch);

              while (ch != 'N' && ch != 'Y') {

                      cout << "Error!!!Incorrect oprion.Re-enter" << endl;

                      cout << "\n Do you want to enter other child informaton(y/n): ";

                      cin >> ch;

                      ch = toupper(ch);

              }

       } while (ch == 'Y');

       cout << "\nTerminating Application!!!" << endl;

       return 0;

}

//Function to get information of a child from user

void getInformation(string& fname, string& lname, int& id, int& wkNum, string& tfname, string& tlname, int& roomNum) {

       cout << "Enter child's first name: ";

       cin >> fname;

       cout << "Enter child's last name: ";

       cin >> lname;

       cout << "Enter child's id: ";

       cin >> id;

       cout << "Enter weeks child' attended: ";

       cin >> wkNum;

       cout << "Enter teacher's first name: ";

       cin >> tfname;

       cout << "Enter teacher's last name: ";

       cin >> tlname;

       cout << "Enter class room number: ";

       cin >> roomNum;

}

//end of main.cpp

Output:

Add a comment
Know the answer?
Add Answer to:
I need to get this two last parts of my project done by tonight. If you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Hello I need some help with my CC+ project. My current project erasing the first two...

    Hello I need some help with my CC+ project. My current project erasing the first two phone numbers and only printing the 3rd phone number out in the list. Any idea on how to correct. Here is the error. Contacts.h #ifndef Contact_H #define Contact_H #include<string> using namespace std; class ContactNode{ public: ContactNode(); ContactNode(string name, string phone); void InsertAfter(ContactNode*); string GetName(); string GetPhoneNumber(); ContactNode* GetNext(); void PrintContactNode(); private: string contactName; string contactPhoneNum; ContactNode* nextNodePtr; }; #endif Contacts.cpp #include <iostream> #include "Contacts.h"...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • How could I separate the following code to where I have a gradebook.cpp and gradebook.h file?...

    How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...

  • I created a struct for Car and now I need to turn it into a class...

    I created a struct for Car and now I need to turn it into a class for Car. Below is the code that I wrote for the structure. For the class, we are suppose to make the data in the class Car private, revise the input so the input function will only read the data from the user, and then it will call an additional function named setUpCar which will put the data into the object. Not sure how to...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT