logo

Rate of Acceleration Physics Assignment 2022

   

Added on  2022-10-02

6 Pages960 Words17 Views
Source Code
#include <iostream>
#include <string>
#include<stdio.h>
#include<conio.h>
using namespace std;
class Bike1
{
private:
int accln;
int speed;
string model;
public:
Bike1()
{
cout<<"Enter Model Name:"<<endl;
getline(cin,model);
accln=3;
speed=0;
}
void getdetails()
{
cout<<"The Details of the bike are:\n";
cout<<"Model Name:"<<model<<endl;
cout<<"Rate of Acceleration:"<<accln<<"m/s^2"<<endl;
}
int accelerate()
{
speed=speed+accln;
return speed;
}
int brake()
{
speed = speed-accln;
return speed;
}
int start()
{
return accelerate();
}
int stop()
{
speed=0;
return speed;

}
};
class Bike2
{
private:
int accln;
int speed;
string model;
public:
Bike2()
{
cout<<"Enter Model Name:"<<endl;
getline(cin,model);
accln=5;
speed=0;
}
void getdetails()
{
cout<<"The Details of the bike are:\n";
cout<<"Model Name:"<<model<<endl;
cout<<"Rate of Acceleration:"<<accln<<"m/s^2"<<endl;
}
int accelerate()
{
speed=speed+accln;
return speed;
}
int brake()
{
speed = speed-accln;
return speed;
}
int start()
{
return accelerate();
}
int stop()
{
speed=0;
return speed;
}
};
int WinMain()
{
int d,t1=0,t2=0,flag=0,s1=0,s2=0,d1=0,d2=0;
char ch;

cout<<"Enter the details of 1st Bike:"<<endl;
Bike1 obj1;
cout<<"Enter the details of 2st Bike:"<<endl;
Bike2 obj2;
cout<<"Enter the distance to be covered by the bikes(in metres):";
cin>>d;
cout<<"You are controlling the 1st Bike! Press W to accelerate , S to
brake , D to start and A to stop !"<<endl;
cout<<"Timestamp(sec)\tSpeed(km/hr)\tDistance Travelled"<<endl;
while(1)
{
ch=getch();
if(ch=='d' || flag==1)
{
flag=1;
switch(ch)
{
case'w':
s1=obj1.accelerate();
t1++;
d1=d1+s1;
break;
case's':
if(s1==0)
{
cout<<"Bike is already
stopped !"<<endl;
break;
}
s1=obj1.brake();
t1++;
d1=d1+s1;
break;
case'd':
if(s1>0)
{
cout<<"Wrong Input !"<<endl;
break;
}
s1=obj1.start();
t1++;
d1=d1+s1;
break;
case 'a':
s1=obj1.stop();
t1++;

End of preview

Want to access all the pages? Upload your documents or become a member.