Question

In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class...

In c++ Please.

Now take your Project 4 and modify it.  You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files.  One (.h) file for the class definitions, both of them.  The class implementation file which has the member function definitions. And the main project file where your main function resides.  Don’t forget to display it when you display the answers.

Project 4 – “You are going to convert feet and inches or pounds in this program.  You will give the user the choice of converting feet and inches to centimeters or pounds to kilograms.  With the correct answer you will also display the number entered.  Create a menu for the user.  Give them the opportunity to convert either as many times as they want, but they must convert at least once.  Add a class and place your private data members in it as well as the member functions for conversion. Not the menu function.  Remember the class should be focused around one thing and that is the conversion.”

formulas:

feet

=

cm div 30.48

inches

=

(cm mod 30.48) / 2.54

lbs

=

kg / 0.45359

cm

=

(feet * 30.48) + (inches * 2.54)

kg

=

lbs * 0.45359

Please note:
div ist the division without remainder whereas mod returns the remainder.
For instance:
7 divided by 3 equals 2 remainder 1 and therefore
7 div 3 = 2 and
7 mod 3 = 1


units:

1 foot

=

30.48 cm

1 inch

=

2.54 cm

1 lbs

=

0.45359 kg

1 cm

=

0.3937 inches

1 kg

=

2.2046 lbs

My coding from project 4 :-

#include <iostream>

using namespace std;

class Conversion

{

public:

double feetInchesToCms(double feetInches)

{

return feetInches*30.48;

}

double poundsToKgs(double pounds)

{

return pounds*0.45359;

}

};

int main()

{

int choice;

while (true)

{

cout << "\n-- Menu --" << endl;

cout << "1.Feet Inches to Cms" << endl;

cout << "2.Pounds to Kgs" << endl;

cout << "3.Quit" << endl;

cout << "Enter Choice of Conversion :";

cin >> choice;

switch (choice)

{

case 1: {

double feetInches;

Conversion c;

cout << "Enter Feet Inches:";

cin >> feetInches;

cout << feetInches << " feet Inches are " << c.feetInchesToCms(feetInches) << " cms." << endl;

continue;

}

case 2: {

double pounds;

Conversion c;

cout << "Enter Pounds :";

cin >> pounds;

cout << pounds << " pounds are " << c.poundsToKgs(pounds) << " kgs." << endl;

continue;

}

case 3: {

break;

}

default: {

cout << "Invalid Choice." << endl;

continue;

}

}

break;

}

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doutbs, please give me comment...

conversion.h

#ifndef CONVERSION_H

#define CONVERSION_H

class Conversion

{

private:

double dimen;

public:

Conversion(double dim);

double feetInchesToCms() const;

double poundsToKgs() const;

};

#include "conversion.cpp"

#endif

conversion.cpp

#include "conversion.h"

Conversion::Conversion(double dim){

dimen = dim;

}

double Conversion::feetInchesToCms() const

{

return dimen*30.48;

}

double Conversion::poundsToKgs() const

{

return dimen*0.45359;

}

conversion_main.cpp

#include <iostream>

#include "conversion.h"

using namespace std;

int main() {

int choice;

while (true) {

cout << "\n-- Menu --" << endl;

cout << "1.Feet Inches to Cms" << endl;

cout << "2.Pounds to Kgs" << endl;

cout << "3.Quit" << endl;

cout << "Enter Choice of Conversion :";

cin >> choice;

switch (choice) {

case 1: {

double feetInches;

cout << "Enter Feet Inches:";

cin >> feetInches;

Conversion c(feetInches);

cout << feetInches << " feet Inches are " << c.feetInchesToCms()

<< " cms." << endl;

continue;

}

case 2: {

double pounds;

cout << "Enter Pounds :";

cin >> pounds;

Conversion c(pounds);

cout << pounds << " pounds are " << c.poundsToKgs() << " kgs."

<< endl;

continue;

}

case 3: {

break;

}

default: {

cout << "Invalid Choice." << endl;

continue;

}

}

break;

}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class...
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
  • Language: C# In this assignment we are going to convert weight and height. So, the user...

    Language: C# In this assignment we are going to convert weight and height. So, the user will have the ability to convert either weight or height and as many times as they want. There conversions will only be one way. By that I mean that you will only convert Pounds to Kilograms and Feet and Inches to Centimeters. NOT the other direction (i.e. to Pounds). There will be 3 options that do the conversion, one for each type of loop....

  • C++ Project Modify the Date Class: Standards Your program must start with comments giving your name...

    C++ Project Modify the Date Class: Standards Your program must start with comments giving your name and the name of the assignment. Your program must use good variable names. All input must have a good prompt so that the user knows what to enter. All output must clearly describe what is output. Using the date class, make the following modifications: Make the thanksgiving function you wrote for project 1 into a method of the Date class. It receive the current...

  • Rework this project to include a class. As explained in class, your project should have its...

    Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...

  • In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits&gt...

    In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...

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