Question

In: Computer Science

NOTE - Submission in parts. Parts required - Dog Class Code, Dog Manager Class Code and...

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:

  1. Add dog
  2. View all dogs
  3. View all available dogs
  4. View dog
  5. Update dog home status
  6. exit

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.

Solutions

Expert Solution

#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;
          
       }
      
   }
}


Related Solutions

SOLUTION IN JAVA LANGUANGE NEEDED. JAVA LANGUAGE QUESTION. NOTE - Submission in parts. Parts required -...
SOLUTION IN JAVA LANGUANGE NEEDED. JAVA LANGUAGE QUESTION. 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...
This project will be submitted in 3 parts. The submission dates and required parts to be...
This project will be submitted in 3 parts. The submission dates and required parts to be completed for each submission are:    Submission 1 - due Monday September 10 before 5pm - You must submit your completed July Journal entries, the Worksheet complete through the Trial Balance, and the worksheet formulas tab complete through the Trial Balance. Your file must be named correctly - "Your name (first and last) Project 1 part 1. Failure to name your file correctly will result...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function for the radius variable. • getRadius. An acccssor function...
C++ Code Required to Show The constructor of parent class executes before child class
C++ Code Required to Show The constructor of parent class executes before child class
Please provide the missng code(parts) for the given code in java. ASAP. import java.util.Stack; class StackQueue<T>...
Please provide the missng code(parts) for the given code in java. ASAP. import java.util.Stack; class StackQueue<T> implements Queue<T>{ private Stack<T> inStack; private Stack<T> outStack; private int size; public StackQueue(){ inStack = new Stack<T> (); outStack = PART(a); size = 0; } public int size(){ return size; } public boolean isEmpty(){ return size==0; } public T first(){ if (size == 0) return null;; if (outStack.empty()) while (!inStack.empty()) outStack.push(inStack.pop()); return PART(b); //return the element at the top of the outStack without removing...
4. Modify the program geometryDemo to use the class basicGeometry and the threeSides code. Note from...
4. Modify the program geometryDemo to use the class basicGeometry and the threeSides code. Note from the comments in the main routine that it wants an input argument of 3 to solve for a triangle and 4 to solve for a square or rectangle. MODIFY the code to add another method in the 'threeSides' and 'fourSides' classes to return the perimeter. ASSUME the following for TRIANGLES. ** for AREA (1/2 * base * height) dimension1 is base, dimension2 is height...
COMPLETE JAVA CODE: public final class Vector2 {       // NOTE:    Before you get...
COMPLETE JAVA CODE: public final class Vector2 {       // NOTE:    Before you get started with the constructors, implement the class variables and    // =====   the accessor methods (getX,getY). The tester for the constructors relies on these    //           methods being implemented. After this, move ahead with the constructors          // class variables here       COMPLETE JAVA CODE: /** * Creates the vector <code>(0.0, 0.0)</code>. */ public Vector2() {       COMPLETE...
Note- can you please rewrite the code in C++ Write a class declaration named Circle with...
Note- can you please rewrite the code in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius
Venn Diagram - The Silversnake class, the Jellyfish class, and the Radical Dog-Star class (kindergartners and...
Venn Diagram - The Silversnake class, the Jellyfish class, and the Radical Dog-Star class (kindergartners and first- and second-graders) were talking about their favorite field trips during the school year. One of the teachers, Ms. Burke, turned the discussion into a math lesson, and the students conducted a survey. Each child wrote down on paper which trip was his or her favorite. (Note that many children named more than one field trip as their favorite.) The survey revealed that 52...
Write a Java class called Employee (Parts of the code is given below), which has three...
Write a Java class called Employee (Parts of the code is given below), which has three private fields firstName (String), lastName (String) and yearsEmployed (double). Implement accessor/mutator methods for the private fields and toString() method, that returns a String representation, which contains employee name and years she was employed. public class Employee { private String firstName; ... } Write a client program called EmployeeClient that creates an instance of Employee class, sets values for the fields (name: John Doe, yearsEmployed:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT