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:
public members:
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;
// 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:

I need to get this two last parts of my project done by tonight. If you...
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 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 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 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; 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;...
i have problem where the address is not save to my file after i input a new address and exit it #include<string> #include<iostream> #include<fstream> #include<sstream> using namespace std; typedef struct date { int day; int month; int year; }Date; typedef struct add { string building; string street; string city; string state; string zip; }Address; typedef struct entry { string firstName; string lastName; Address address; string phNo; Date...
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...
So I'm not sure what I'm trying to do here. I don't understand how *adr works, I guess it's a pointer to the struct Address. How do I complete this function? And how would I have it just return the zip code or one element if I wanted to? I have two structs: struct Address { int number; // street number string street; // street Name string city; // city short zip; // zip code ...
The project I have is a link list that asks for a name and phone number and it allows the user to insert ,delete ,modify ,and find an element in the structure. The program has a menu in which the user can choose which function they want to use I need to use switch case to do this but it has not worked I need help with this. Thank you! #include <iostream> #include <string> #include <iomanip> using namespace std; const int...