Question

Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the...

Please Help. C++.

Need 3 attributes and 3 methods added to the code below.

Need the prototype added to the .h file......and the implementation in the .cpp file....thanks!

edited: I just need the above and then I was told to use the methods in the main program; for the vehicle. Any 3 attributes and any three methofds.

source.cpp file

// Header Comment

#include

#include

#include

#include "Automobile.h"

using namespace std;

struct Address{

string street;

string city;

string state;

string zip;

};

struct Student{

string id;

string name;

Address homeAddress;

int numCredits; // total attempted credits

double gpa; // 4.0 scale

};

void boostGPA(const Student &s);

int main(){

vector carList;

{

Automobile spencerMobile("Yugo", "PutPut", 2004);

spencerMobile.drive(60);

}

system("pause");

return 0;

}

void boostGPA(const Student &s){

cout << s.gpa;

}

-------------automobile.cpp file

#include

#include "Automobile.h"

using namespace std;

Automobile::Automobile(string carMake, string carModel, int year){

make = carMake;

model = carModel;

this->year = year;

mileage = 0;

mpg = 44;

fuelLevel = 10;

}

void Automobile::drive(double distance){

if ((distance > 0) && (distance <= fuelLevel*mpg)){

mileage += distance;

fuelLevel -= distance / mpg;

}

}

double Automobile::getMileage(){

return mileage;

}

-------automobile.h file

#include

#include

using namespace std;

class Automobile{

private:

string make;

string model;

int year;

double mileage;

double fuelLevel;

double mpg;

public:

Automobile(string carMake, string carModel, int year);

~Automobile(){

// check for passengers

//check for valuables in trunk

// release memory

if (fuelLevel > 0)

cout << "recovering " << fuelLevel << "

gallons of fuel\n";

cout << "Destroy " << make << " " << model << endl;

}

void drive(double distance);

double getMileage();

};

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

Your question isn't clear but I have tried to make sense out it, the best I could.

/***********************Automobile.h*************************/

#include <string>

using namespace std;

class Automobile {

private:

int passengers;

/*

stores the number od passengers in the automobile

*/

int valuables;

/*

stores the price of the valuables in the trunk

*/

int weight;

/*

stores the weight of the car

*/

string make;

string model;

int year;

double mileage;

double fuelLevel;

double mpg;

public:

Automobile(string carMake, string carModel, int year, int passengers, int valuables);

~Automobile();

void drive(double distance);

double getMileage();

void displayInfo();

/*

displays info abput the car

*/

void refill(double fuel);

int getPassengers();

/*

gets the number of passengers in the automobile

*/

int getValuables();

/*

gets the cost of valuables in the trunk

*/

};

/**********************Automobile.cpp***********************/

#include <iostream>

#include <string>

#include "Automobile.h"

using namespace std;

Automobile::Automobile(string carMake, string carModel, int year, int passengers, int valuables){

this->passengers = passengers;

this->valuables = valuables;

/*

'this' pointes to the calling object

(the automobile object in this case)

*/

make = carMake;

model = carModel;

this->year = year;

mileage = 0;

mpg = 44;

fuelLevel = 10;

}

void Automobile::drive(double distance){

if ((distance > 0) && (distance <= fuelLevel * mpg)){

mileage += distance;

fuelLevel -= distance / mpg;

}

}

void Automobile::refill(double fuel) {

fuelLevel += fuel;

}

double Automobile::getMileage(){

return mileage;

}

int Automobile::getPassengers(){

return passengers;

}

int Automobile::getValuables(){

return valuables;

}

void Automobile::displayInfo() {

cout<<"Make: "<<make<<endl;

cout<<"Model: "<<model<<endl;

cout<<"Year: "<<year<<endl;

cout<<"Mileage: "<<mileage<<endl;

cout<<"Fuel Level: "<<fuelLevel<<endl;

cout<<"Miles per gallon: "<<mpg<<endl<<endl;

}

Automobile::~Automobile(){

if(getPassengers() > 0) {

cout<<"warning: destroying automobile with passengers inside"<<endl;

}

/*

checks if there are passengers inside the automobile

*/

if(getValuables() > 100) {

cout<<"warning: destroying automobile with expensive valuables in trunk"<<endl;

}

//check for valuables in trunk

if (fuelLevel > 0)

cout << "recovering " << fuelLevel << " gallons of fuel\n";

cout << "Destroy " << make << " " << model << endl;

}

/***********************main.cpp*************************/

#include <iostream>

/*

used to implement cout and cin for input and output

*/

#include "Automobile.h"

using namespace std;

int main(){

Automobile spencerMobile1("Yugo", "PutPut", 2004, 0, 95);

Automobile spencerMobile2("Suzuki", "Vitara", 2018, 4, 105);

spencerMobile1.displayInfo();

spencerMobile2.displayInfo();

spencerMobile1.drive(60);

spencerMobile2.drive(30);

cout<<"After driving:"<<endl;

spencerMobile1.displayInfo();

spencerMobile2.displayInfo();

spencerMobile1.refill(3);

spencerMobile2.refill(3);

cout<<"After fueling:"<<endl;

spencerMobile1.displayInfo();

spencerMobile2.displayInfo();

cout<<"Quitting...";

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the...
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
  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • [C++] Please help to understand why this code need to have "void calcSales(CorpData &);" and "void...

    [C++] Please help to understand why this code need to have "void calcSales(CorpData &);" and "void displayDivInfo(CorpData);". Thanks! ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #include <iostream> #include <string> using namespace std; struct CorpData { string diviName; double firstQua, secondQua, thirdQua, fourthQua, annualSales, quaAvg;    CorpData(string d, double fq, double sq, double tq, double frq) { diviName = d; firstQua = fq; secondQua = sq; thirdQua = tq; fourthQua = frq; } }; void calcSales(CorpData &); void displayDivInfo(CorpData); int main() {    CorpData West("West", 10000, 20000,...

  • hello there. can you please help me to complete this code. thank you. Lab #3 -...

    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() {          ...

  • I need help with the code below. It is a C program, NOT C++. It can...

    I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...

  • This is for my c++ class and I would really appreciate the help, Thank you! Complete...

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

  • I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instruction...

    I need help modifying this code please ASAP using C++ Here is what I missed on this code below Here are the instructions Here is the code Produce correct70 pts O pts Full Marks No Marks results and statisfy requirements view longer Comments 1. Your display amount is not readable 2. I withdraw more than my balance, but I didn't see any error message description Documentations10 pts 0 pts Full Marks No Marks : comment i code and block comment...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • I cannot get the C++ code below to compile correctly. Any assistance would be greatly appreciated!...

    I cannot get the C++ code below to compile correctly. Any assistance would be greatly appreciated! ***main.cpp driver file*** #include #include #include "vector.h" using namespace std; int main() {     vectorInfo v1(3, -1);     vectorInfo v2(2, 3);     cout << "v1 : ";     v1.print();     cout << "v2 : ";     v2.print();     cout << "v1 magnitude : " << v1.magnitude() << endl;     cout << "v1 direction : " << v1.direction() << " radians" << endl;     cout...

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