car

Write a class car that contains attributes of car’s name (type string), top speed (type float) and model name (type string). A constructor with no arguments initializes the data members and two-member functions to input and display these attributes.

 

#include<iostream>
#include<conio.h>
#include<string.h>

using namespace std;

class car{

  private:
       string name, model;
       float top_speed;
  public:
       car(){
            name=model="NULL";
            top_speed=0;  
       }
       void input(){
            cout<<"Enter Car Name:";
            cin>>name;
            cout<<"Enter Car Model:";
            cin>>model;
            cout<<"Enter Top Speed of Car:";
            cin>>top_speed;
       }
       void display(){
            cout<<"Name of car:"<<name<<endl<<"Model of Car:"<<model<<endl;
            cout<<"Top Speed:"<<top_speed;
       }
};

int main(){
  car c1;
  c1.input();
  c1.display();
  getch();
  return 0;
}   

1 Comment

  • Dhruvjohn Samuel

    It’s a very good solution.

Leave a Reply

Your email address will not be published. Required fields are marked *