In: Computer Science
NOTE - Submission in parts. Parts required - Dog Class Code, Dog
Manager Class Code and the main code. Please differentiate all
three in the answer.
This Assignment is designed to take you through the process of creating basic classes, aggregation and manipulating arrays of objects.
Scenario:
A dog shelter would like a simple system to keep track of all the dogs that pass through the facility.
The system must record for each dog:
dogId (int) - must be unique
name (string)
age (double) - cannot be less than 0 or more than 25
breed (string)
sex (char) – m for male, f for female
foundHome (bool) - true means the dogs has been places in a home false otherwise.
You must create an object oriented solution with a text based menu as summarized on the next page. The system must check that valid data is entered. For example, the menu has four items so only 1 to 5 must be allowed as input from the menu.
Summary of Operations
System Menu:
Overview:
Add Dog:
When a dog is added to the system, you must check that the dogId is not already used in the system. All new dogs have no home as yet (foundHome = false).
View all Dogs:
This menu option shows all dogs in the system. This includes dogs that have a home and those that do not.
View all available dogs:
Shows all dogs in the system, that have no homes as yet.
View dog:
Asks the user for a dogId and then displays the dog information if found and “There is no dog with that id..” if it is not found.
Update dog home status:
Asks the user for a dogId. If a dog with that id is found, the “foundHome” status is changed to true and the dog information is to be displayed. If the dog is not found the message “There is no dog with that id..” should be displayed.
#include<bits/stdc++.h>
using namespace std;
//dog class code
class dog{
public:
int dogID;
string name;
double age;
string breed;
char sex;
bool foundHome;
dog(int dogID,string name,double
age,string breed,char sex,bool foundHome)
{
dogID=dogID,name=name,age=age,breed=breed,sex=sex,foundHome=foundHome;
}
};
//dog manager class code
class dog_manager{
public:
dog a[100];
int n;
void addDog(int dogID,string
name,double age,string breed,char sex,bool foundhome)
{
bool
flag=false;
for(int
i=0;i<n;i++)
{
if(a[i].dogID==dogID)
{
flag=false;
}
else{
if(a[i].foundHome==false)
{
flag=true;
}
else
{
flag=false;
}
}
}
if(flag==false)
{
cout<<"dog already
exist"<<endl;
return;
}
n++;
a[n]=dog(dogID,name,age,breed,sex,foundHome);
}
void viewAllDogs(){
for(int
i=0;i<n;i++)
{
cout<<a[i].dogID<<"
"<<a[i].name<<" "<<a[i].age<<"
"<<a[i].breed<<" "<<a[i].sex<<"
"<<a[i].foundHome<<endl;
}
}
void viewAllAvailableDogs(){
for(int
i=0;i<n;i++)
{
if(a[i].foundHome==false)
{
cout<<a[i].dogID<<" "<<a[i].name<<"
"<<a[i].age<<" "<<a[i].breed<<"
"<<a[i].sex<<"
"<<a[i].foundHome<<endl;
}
}
}
void viewDog(int dogID)
{
bool
flag=false;
for(int
i=0;i<n;i++)
{
if(a[i].dogID==dogID)
{
cout<<a[i].dogID<<"
"<<a[i].name<<" "<<a[i].age<<"
"<<a[i].breed<<" "<<a[i].sex<<"
"<<a[i].foundHome<<endl;
flag=true;
}
}
if(flag==false)
cout<<"There is no dog with that id :
"<<dogID<<endl;
}
void updateStatus(int dogID)
{
bool
flag=false;
for(int
i=0;i<n;i++)
{
if(a[i].dogID==dogID)
{
a[i].foundHome=true;
cout<<a[i].dogID<<" "<<a[i].name<<"
"<<a[i].age<<" "<<a[i].breed<<"
"<<a[i].sex<<"
"<<a[i].foundHome<<endl;
flag=true;
}
}
if(flag==false)
cout<<"There is no dog with that id :
"<<dogID<<endl;
}
};
//main function code
main(){
dog_manager d;
cout<<"1.Add dog\n2.View all dogs\n3.view all
available dogs\n4.view dog\n5.update dog home
status\n6.exit"<<endl;
cout<<"enter your choice:"<<endl;
int choice;
cin>>choice;
while(1)
{
bool flag=false;
switch(choice){
case 1:
int dogID;
string name;
double age;
char sex;
string breed;
bool foundHome;
cout<<"enter the details of the
dog"<<endl;
cin>>dogID>>name>>age>>breed>>sex>>foundHome;
d.addDog(dogID,name,age,breed,sex,foundHome);
break;
case 2:
d.viewAllDogs();
break;
case 3:
d.viewAllAvailableDogs();
break;
case 4:
int dogID;
cout<<"enter the dogID"<<endl;
cin>>dogID;
d.viewDog(dogID);
break;
case 5:
int dogID;
cout<<"enter the dogID"<<endl;
cin>>dogID;
d.updateStatus(dogID);
break;
case 6:
flag=true;
}
if(flag==true)
break;
else
{
cout<<"1.Add dog\n2.View all
dogs\n3.view all available dogs\n4.view dog\n5.update dog home
status\n6.exit"<<endl;
cout<<"enter your
choice:"<<endl;
int choice;
cin>>choice;
}
}
}