C++ Practice: Answer Whichever you can & it'll help a lot. Thank you!
Question 1. Implement the constructors and member function of each of the classes (Marks 15)
class Fraction{
private:
int numerator;
int denominator;
public:
Fraction(int, int);
float fractionValue();//determines the value of numerator/denominator
};
class Problem{
private:
Fraction f[3];
public:
Problem(int, int, int, int, int, int);
Fraction largestFraction();//Returns the fraction having largest fraction value
};
Question 2: In the following Inheritance problem
#include<iostream>
#include<string>
using namespace std;
class Animal{
protected:
int height;
int age;
double weight;
public:
Animal(int , int , double);
void print()const;
};
class Dog: private Animal{
protected :
string dogType;
public:
Dog(int , int, double, string);
void print()const;
};
class GermanShephard: private Dog{
private:
string name;
public:
GermanShephard(int , int , double , string , string);
void print()const;
};
int main(){
GermanShephard ms(61, 5, 30.5, "pet", "Coco");
return 0;
}
a. Complete the implementation file of each classes (Marks 15)
b. What is the sequence of call of constructors and destructors when objects ms is called
(Marks 5)
Question 3: In the following problem
#include<iostream>
using namespace std;
class Point{
private:
int x;
int y;
public:
Point();
void print()const;
void setf(int, int);
};
class Line{
private:
Point ps;
Point pe;
public:
Line();
void print()const;
void setf(int, int, int, int);
};
class Rectangle{
private:
Line length[2];
Line width[2];
public:
Rectangle();
void print()const;
void setf(int, int, int, int, int, int, int, int);
};
int main(){
Rectangle r1;
r1.setf(3,4,5,6, 7, 8, 9, 10);
r1.print();
system("pause");
return 0;
}
a. Write implementation of the functions of Rectangle, Line and Point class(Marks 15)
b. What is the call of constructor of Point, Line and Rectangle when r1 is created? What is
the call of destructor of Point, Line and Rectangle when r1 goes out of scope?(Marks 10)
class Fraction{
private:
int numerator;
int denominator;
public:
Fraction(int n, int d) {
numerator = n;
denominator = d;
}
// this default constructor is required else,
// Problem class code will not even compile.
Fraction() {
numerator = 0;
denominator = 1;
}
float fractionValue() {
return numerator/ (float) denominator;
}
void setNumerator(int n) {
numerator = n;
}
void setDenominator(int d) {
denominator = d;
}
};
class Problem{
private:
Fraction f[3];
public:
Problem(int n1, int d1, int n2, int d2, int n3, int d3) {
f[0].setNumerator(n1);
f[0].setDenominator(d1);
f[1].setNumerator(n2);
f[1].setDenominator(d2);
f[2].setNumerator(n3);
f[2].setDenominator(d3);
}
Fraction largestFraction() {
if(f[0].fractionValue() > f[1].fractionValue()) {
if(f[0].fractionValue() > f[2].fractionValue()) {
return f[0];
} else {
return f[2];
}
} else {
if(f[1].fractionValue() > f[2].fractionValue()) {
return f[1];
} else {
return f[2];
}
}
}
};
************************************************** Sir, in the given time i can only solve one question as per HomeworkLib terms and conditions, since each question contains a separate question.. however, i have answered the first question in detail, and implemented each and every function required in that.. let me know if any issues. Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement...
Can you turn this code into a
C++ class diagram?
Animals.h #1 fndef ANIMALS-H #define ANIMALSH #include <string> class Animal { - public: Animal (const std::string&name: fName( name virtual void Speak O const0 th protected: std::string fName; !; // class Animal class Dogpublic Animal public: Dog (const std::string& nameAnimal ( name virtual void SpeakO const; //class Dog class Cat public Animal f public: Cat ( const std::string& nameAnimal(name) t virtual void Speak O const; 1; // class Cat class Tiger:public...
This is for my c++ class and I would really appreciate the help, Thank you! Complete the definitions of the functions for the ConcessionStand class in the ConcessionStand.cpp file. The class definition and function prototypes are in the provided ConcessionStand.h header file. A testing program is in the provided main.cpp file. You don’t need to change anything in ConcessionStand.h or main.cpp, unless you want to play with different options in the main.cpp program. ___________________ Main.cpp ____________________ #include "ConcessionStand.h" #include <iostream>...
Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...
hello there. can you please help me to complete this code. thank you. Lab #3 - Classes/Constructors Part I - Fill in the missing parts of this code #include<iostream> #include<string> #include<fstream> using namespace std; class classGrades { public: void printlist() const; void inputGrades(ifstream &); double returnAvg() const; void setName(string); void setNumStudents(int); classGrades(); classGrades(int); private: int gradeList[30]; int numStudents; string name; }; int main() { ...
solve it in c++ 10
note:
please do not give me same answer like this
1. Define a Pet class that stores the pet's name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value "unknown lifespan." Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add...
C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will work with 2 classes to be used in a RPG videogame. The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods: a constructor Character(string Name, string Race), that will set the values for the name and the race variables set/get functions for the two attributes a function 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...
Please implement the following problem in basic C++ code and
include detailed comments so that I am able to understand the
processes for the solution. Thanks in advance.
// personType.h
#include <string>
using namespace std;
class personType
{
public:
virtual void print() const;
void setName(string first, string last);
string getFirstName() const;
string getLastName() const;
personType(string first = "", string last = "");
protected:
string firstName;
string lastName;
};
// personTypeImp.cpp
#include <iostream>
#include <string>
#include "personType.h"
using namespace std;
void...
Hello, im looking for help on adding overload operators to my code. It needs to consist of + (addition) for the Fraction class * (multiplication), no need not reduce == (equality operator) = (assignment operator) << and >> so in main you can use << and >> as follows: cin>>frac1; cout<< frac1; where frac1 is a an object of the Fraction class the original code is: #include <iostream> using namespace std; class Fractions { private: int numerator; int denominator;...
c++
Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...