Question

Hi, I need to write a program for linux (putty) and please read carefully (I've asked the same question 3 times because the experts who answered my questions wrote their own carmain1.cpp file. Please leave it where it is and only create car.cpp and car.h files.)

Exercise 1: Car class (5 points) Create a header file ( car.h ) with a class definition for a Car object. A Car object will h

Here's carmain1.cppEXAMPLE OUTPUT #1 Sedan before initialization: Make: Model: Year: 1312323184 Setting values for sedan: Enter make: Honda Ente

/* carmain1.cpp
* Please don't rewrite this file
* I will be using the exact
* same file below when grading
*
*/

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

using namespace std;

int main()
{
   Car sedan;

// input
string imake;
string imodel;
int iyear;

// output
string omake;
string omodel;
int oyear;
  
// getting values before setting them.
// This may produce garbage values. We will be
// fixing this in exercise 2.
cout << "Sedan before initialization: " << endl;
omake = sedan.getMake();
cout << "Make: " << omake << endl;

omodel = sedan.getModel();
cout << "Model: " << omodel << endl;

oyear = sedan.getYear();
cout << "Year: " << oyear << endl;
  
//set the values for sedan
cout << "Setting values for sedan: " << endl;
cout << "Enter make: ";
getline(cin, imake);
sedan.setMake(imake);

cout << "Enter model: ";
getline(cin, imodel);
sedan.setModel(imodel);
  
cout << "Enter year: ";
cin >> iyear;
cin.ignore(200, '\n');
sedan.setYear(iyear);

// getting the data back out
cout << "printing values for sedan: " << endl;
omake = sedan.getMake();
cout << "Make: " << omake << endl;

omodel = sedan.getModel();
cout << "Model: " << omodel << endl;

oyear = sedan.getYear();
cout << "Year: " << oyear << endl;
  
return 0;   
}
  
  

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

//C++ Code

/*============car.h====================*/
#ifndef _CAR_H_
#define _CAR_H_
#include<iostream>
using namespace std;
class Car
{
private:
   //member variables
   string make;
   string model;
   int year;
public:
   //default constructor
   Car();
   //getters
   string getMake()const;
   string getModel() const;
   int getYear()const;
   //setters
   void setMake(const string mk);
   void setModel(const string md);
   void setYear(const int yr);

};
#endif

/*================car.cpp======================*/
#include"car.h"
Car::Car()
{
   make = "";
   model = "";
   year = 1312323184;
}
//getters
string Car::getMake()const
{
   return make;
}
string Car::getModel() const
{
   return model;
}
int Car::getYear()const
{
   return year;
}
//setters
void Car::setMake(const string mk)
{
   make = mk;
}
void Car::setModel(const string md)
{
   model = md;
}
void Car::setYear(const int yr)
{
   year = yr;
}

/* carmain1.cpp
* Please don't rewrite this file
* I will be using the exact
* same file below when grading
*
*/
/*===============carmain1.cpp======================*/
#include <iostream>
#include "car.h"
#include<string>
using namespace std;

int main()
{
   Car sedan;

   // input
   string imake;
   string imodel;
   int iyear;

   // output
   string omake;
   string omodel;
   int oyear;

   // getting values before setting them.
   // This may produce garbage values. We will be
   // fixing this in exercise 2.
   cout << "Sedan before initialization: " << endl;
   omake = sedan.getMake();
   cout << "Make: " << omake << endl;

   omodel = sedan.getModel();
   cout << "Model: " << omodel << endl;

   oyear = sedan.getYear();
   cout << "Year: " << oyear << endl;

   //set the values for sedan
   cout << "Setting values for sedan: " << endl;
   cout << "Enter make: ";
   getline(cin, imake);
   sedan.setMake(imake);

   cout << "Enter model: ";
   getline(cin, imodel);
   sedan.setModel(imodel);

   cout << "Enter year: ";
   cin >> iyear;
   cin.ignore(200, '\n');
   sedan.setYear(iyear);

   // getting the data back out
   cout << "printing values for sedan: " << endl;
   omake = sedan.getMake();
   cout << "Make: " << omake << endl;

   omodel = sedan.getModel();
   cout << "Model: " << omodel << endl;

   oyear = sedan.getYear();
   cout << "Year: " << oyear << endl;

   return 0;
}

//Output

Sedan before initialization: Make: Model: Year: 1312323184 Setting values for sedan: Enter make: Honda Enter model: Civic Ent

//If you need any help regarding this solution........ please leave a comment...... thanks

Add a comment
Know the answer?
Add Answer to:
Hi, I need to write a program for linux (putty) and please read carefully (I've asked...
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
  • I created a struct for Car and now I need to turn it into a class...

    I created a struct for Car and now I need to turn it into a class for Car. Below is the code that I wrote for the structure. For the class, we are suppose to make the data in the class Car private, revise the input so the input function will only read the data from the user, and then it will call an additional function named setUpCar which will put the data into the object. Not sure how to...

  • ​c++ program that takes user input from the console and store the data into a linked list.

    c++ program that takes user input from the console and store the data into a linked list. The input made of 4 objects associated to a car: model, make, mileage and year. My program should take the how many inputs the user want to make, followed by the inputs themselves. After the input, my program should print the data inside the linked list. So far, the issue is that my program print some of the input, but not all. Input sample:3HondaSentra89002017ToyotaCamri1098271999NissanSentra87261987current...

  • I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program...

    I need help debugging this C++ prgram. What Am i doing wrong? //******************************************************** // This program reads two input files whose lines are //ordered by a key data field. This program should merge //these two files, writing an output file that contains //all lines from both files ordered by the same key field. // //********************************************************* #include <iostream> #include<string> #include<fstream> //prototype void mergeTwoFiles (ifstream&,ifstream&, ofstream&); using namespace std; int main() {string inFile1,inFile2,outFile; // input and output files ifstream in1; ifstream in2;...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • I need to get this two last parts of my project done by tonight. If you...

    I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member fu...

    C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

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
Active Questions
ADVERTISEMENT