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...

  • 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...

  • 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...

  • 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...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data...

    need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data file – It has: player ID, player first name, middle initial, last name soccer.txt – Player information file – It has: player ID, goals scored, number of penalties, jersey number output file - formatted according to the example provided later in this assignment a) Define a struct to hold the information for a person storing first name, middle initial, and   last name). b) Define...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. 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
ADVERTISEMENT