Rate of Acceleration Physics Assignment 2022
VerifiedAdded on  2022/10/02
|6
|960
|17
Assignment
AI Summary
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
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()
{
#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()
{
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
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;
}
};
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++;
{
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++;
break;
default:
cout<<"Wrong Input !"<<endl;
}
if(d1>=d)
d1=d;
cout<<t1<<"\t\t\t"<<s1<<"\t\t"<<d1<<"\t"<<endl;
if(d1==d)
break;
}
}
ch='B';
flag=0;
cout<<"You are controlling the 2nd 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':
s2=obj2.accelerate();
t2++;
d2=d2+s2;
break;
case's':
if(s2==0)
{
cout<<"Bike is already stopped !"<<endl;
break;
}
s2=obj2.brake();
t2++;
d2=d2+s2;
break;
break;
case 'a':
s1=obj1.stop();
t1++;
break;
default:
cout<<"Wrong Input !"<<endl;
}
if(d1>=d)
d1=d;
cout<<t1<<"\t\t\t"<<s1<<"\t\t"<<d1<<"\t"<<endl;
if(d1==d)
break;
}
}
ch='B';
flag=0;
cout<<"You are controlling the 2nd 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':
s2=obj2.accelerate();
t2++;
d2=d2+s2;
break;
case's':
if(s2==0)
{
cout<<"Bike is already stopped !"<<endl;
break;
}
s2=obj2.brake();
t2++;
d2=d2+s2;
break;
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
case'd':
if(s2>0)
{
cout<<"Wrong Input !"<<endl;
break;
}
s2=obj2.start();
t2++;
d2=d2+s2;
break;
case 'a':
s2=obj2.stop();
t2++;
break;
default:
cout<<"Wrong Input !"<<endl;
}
if(d2>=d)
d2=d;
cout<<t2<<"\t\t\t"<<s2<<"\t\t"<<d2<<"\t"<<endl;
if(d2==d)
break;
}
}
if(t1<t2)
cout<<"First bike has won the race !";
if(t2<t1)
cout<<"Second bike has won the race !";
if(t1==t2)
cout<<"It's a tie !'";
return 0;
}
if(s2>0)
{
cout<<"Wrong Input !"<<endl;
break;
}
s2=obj2.start();
t2++;
d2=d2+s2;
break;
case 'a':
s2=obj2.stop();
t2++;
break;
default:
cout<<"Wrong Input !"<<endl;
}
if(d2>=d)
d2=d;
cout<<t2<<"\t\t\t"<<s2<<"\t\t"<<d2<<"\t"<<endl;
if(d2==d)
break;
}
}
if(t1<t2)
cout<<"First bike has won the race !";
if(t2<t1)
cout<<"Second bike has won the race !";
if(t1==t2)
cout<<"It's a tie !'";
return 0;
}
Output
Input for Bike 1
Input for Bike 2
Input for Bike 1
Input for Bike 2
1 out of 6
Your All-in-One AI-Powered Toolkit for Academic Success.
 +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024  |  Zucol Services PVT LTD  |  All rights reserved.