Question

Description: help in c++, this program should have 3 files, TestCat.cpp, Cat.cpp, Cat.h. Write a Cat...

Description: help in c++, this program should have 3 files, TestCat.cpp, Cat.cpp, Cat.h.

  • Write a Cat class to maintain the information about a Cat: name, age, color, furLength, weight. Note that name, color, and furLength are all strings. Age is an integer and Weight is a floating-point numbers.
  • Then write a test program for that class. The test program should read in values for each feature of the cat, set those, and then print them using the Cat’s print method.

Sample Run #1 (bold, underlined text is what the user types):

Name Age Color Fur-Length Weight? Fluffy 3 Grey-Tabby Long-Hair 12.5

Name: Fluffy
Age: 3
Color: Grey-Tabby
Fur Length: Long-Hair
Weight: 12.5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ program to create and test Cat class

// Cat.h

#ifndef CAT_H_
#define CAT_H_

#include <string>
using namespace std;

class Cat
{
private:
   string name;
   string color;
   string furLength ;
   int age;
   double weight;

public:
   Cat();
   Cat(string,string,string,int,double);
   void setName(string);
   void setColor(string);
   void setFurLength(string);
   void setAge(int);
   void setWeight(double);
   string getName();
   string getColor();
   string getFurLength();
   int getAge();
   double getWeight();
   void print();
};
#endif
//end of Cat.h

// Cat.cpp

#include "Cat.h"
#include <iostream>

// default constructor
Cat::Cat() : name(""), color(""), furLength(""),age(0),weight(0)
{}

// parameterized constructor
Cat::Cat(string name, string color, string furLength, int age, double weight): name(name), color(color), furLength(furLength), age(age), weight(weight)
{}

// setters
void Cat::setAge(int age)
{
   this->age = age;
}

void Cat::setName(string name)
{
   this->name = name;
}

void Cat::setColor(string color)
{
   this->color = color;
}

void Cat::setFurLength(string furLength)
{
   this->furLength = furLength;
}

void Cat::setWeight(double weight)
{
   this->weight = weight;
}

// getters
string Cat::getName()
{
   return name;
}

string Cat::getColor()
{
   return color;
}

string Cat::getFurLength()
{
   return furLength;
}

int Cat::getAge()
{
   return age;
}

double Cat::getWeight()
{
   return weight;
}

// function to print the values of the fields
void Cat::print()
{
   cout<<"Name: "<<name<<endl;
   cout<<"Age: "<<age<<endl;
   cout<<"Color: "<<color<<endl;
   cout<<"Fur Length: "<<furLength<<endl;
   cout<<"Weight: "<<weight<<endl;
}
//end of Cat.cpp

// TestCat.cpp

#include "Cat.h"
#include <iostream>
using namespace std;

int main()
{
   string name, color, furLength;
   int age;
   double weight;
   // input of name, age,color,fur length and weight
   // strings input should be without any space
   cout<<"Name Age Color Fur-Length Weight? ";
   cin>>name>>age>>color>>furLength>>weight;
   Cat cat(name,color,furLength,age,weight);
   cout<<endl;
   cat.print();
   return 0;
}
//end of TestCat.cpp

Output:

Add a comment
Know the answer?
Add Answer to:
Description: help in c++, this program should have 3 files, TestCat.cpp, Cat.cpp, Cat.h. Write a Cat...
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
  • Please Help, I will rate either way because of the effort. Description: help in c++, this...

    Please Help, I will rate either way because of the effort. Description: help in c++, this program should have 3 files GuessWho.cpp, Person.cpp, Person.h This program will be a Guess Who game. The program should Read the first line of people.txt, Use the contents to set the members of your Person object, Print the Guess Who People heading, Print the Person that you read earlier Prompt the user for a feature (name, haircolor, hairtype, gender, glasses, eyecolor, or hat) Print...

  • In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double...

    In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double length; double height; double tailLength; string eyeColour; string furClassification; //long, medium, short, none string furColours[5]; }; void initCat (Cat&, double, double, double, string, string, const string[]); void readCat (Cat&); void printCat (const Cat&); bool isCalico (const Cat&); bool isTaller (const Cat&, const Cat&); #endif ***//Cat.cpp//*** #include "Cat.h" #include <iostream> using namespace std; void initCat (Cat& cat, double l, double h, double tL, string eC,...

  • 1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store...

    1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store the number of lives remaining: numLives – Write a constructor that initializes numLives to 9 and initializes name, age, & weight based on formal parameter values 2. Write a main method to test your Cat constructor & call the inherited writeOutput() method 3. Write a new writeOutput method in Cat that uses “super” to print the Cat’s name, age, weight & numLives – Does...

  • previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print...

    previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print the results on console window.*/ //Main.cpp //include header files #include<iostream> //include Animal, Mammal and Cat header files #include "Animal.h" #include "Mammal.h" #include "Cat.h" using namespace std; int main() {    //create Animal object    Animal animal("Dog","Mammal",4);    cout<<"Animal object details"<<endl;    cout<<"Name: "<<animal.getName()<<endl;    cout<<"Type: "<<animal.getType()<<endl;    cout<<"# of Legs: "<<animal.getLegs()<<endl;          cout<<endl<<endl;    //create Cat object    Cat cat("byssinian cat","carnivorous mammal",4,"short...

  • Write a python program using Object Oriented and do the following: 1. create class "cat" with...

    Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...

  • C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types...

    C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types of passenger trains. One train can hold only cats. Another train can hold only wizards. You are going to create a Wizard class, a Cat class, and a Train class. You are provided the driver, lab2.cpp. The Train class should be a template class where the type of passenger is the template data type. Specifications cat class Attributes: name of cat breed of cat...

  • i have to write a program that asks the names of 2 files. the first should...

    i have to write a program that asks the names of 2 files. the first should be open for reading second for writing. the program should read the the contents of the first file change all characters to uppercase and store in the second file. the second file will be a copy of the first file, except that all characters will be uppercase. use notepad to test the program. i got this so far {         String firstfile;         String...

  • WRITE IN PSEUDOCODE USING THE FOLLOWING GUIDELINES Classes Program 1: WAKA, WAKA. Pac-Man was a big...

    WRITE IN PSEUDOCODE USING THE FOLLOWING GUIDELINES Classes Program 1: WAKA, WAKA. Pac-Man was a big hit back in the 80s. One of the things he could do was “teleport” from one side of the screen to the other, and that’s what we’re going to implement here. For this program, you’re going to write a class (called “PacMan”) that only has two attributes: an X and Y location. Imagine the player is on a 10x10 grid and starts at location...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

  • The goal of this homework is to write a small database system for an Animal Shelter....

    The goal of this homework is to write a small database system for an Animal Shelter. This is a no-kill shelter like the one just west of the Addition Airport. You will accept animal “donations” to the shelter, but mostly only dogs and cats. (But yes, there may be the occasional hamster or other nondog, non-cat animal donation.) At present, all we need to do is write the skeleton of a database that will track all the animals in the...

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