You are on page 1of 6

ARUSHA TECHNICAL COLLEGE (ATC)

ELECTRICAL ENGINEERING DEPARTMENT

PROGRAM: DEGREE IN ELECTRICAL AND AUTOMATION ENGINEERING

MODULE NAME: PROGRAMMING IN C++

MODULE CODE: CSU 07101


FACILITATOR: AMON,F

NATURE OF THE TASK: INDIVIDUAL ASSIGNMENT

ADMISSION NUMBER: 21031613105


EXAMINATION NUMBER:
NAME: NURDIN BADI
Table of Contents
1. Simple C++ calculator that + - / * receive 4 number ............................................................. 2
2. Write a C++ code that simulate a Driving of a manual car ................................................... 4
1. Simple C++ calculator that + - / * receive 4 number
a. Should receive four number from the user

b. Should receive operator from the user

c. Should display correct answer

d. Should work free of error and crushing

C++ CODE:

#include <iostream>

using namespace std;

int main(){

cout<<"C++ CALCULATOR THAT RECEIVE FOUR NUMBER FROM


USER"<<endl<<endl;

float num1, num2, num3, num4 ;

char Y, oper ;

cout<<"Enter The First Number: "<<endl;

cin>>num1;

cout<<"Enter The Second Number: "<<endl;

cin>>num2;

cout<<"Enter The Third Number: "<<endl;

cin>>num3;

cout<<"Enter The Fourth Number: "<<endl;

cin>>num4;

cout<<endl;

Y:

cout<<"USER OPERATOR"<<endl<<endl;

cout<<"Press: "<<endl;

cout<<" (/) For DIVISION"<<endl;

2
cout<<" (*) For MULTIPLICATION"<<endl;

cout<<" (+) For ADDITION"<<endl;

cout<<" (-) For SUBSTRACTION"<<endl<<endl;

cout<<"Enter The Operator: "<<endl;

cin>>oper;

switch(oper){

case '+':{

cout<<"Your Addition Answer is : "<<num1+num2+num3+num4;

break;}

case '-':{

cout<<"Your Substraction Answer is : "<<num1-num2-num3-num4;

break; }

case '/':{

cout<<"Your Division Answer is : "<<num1/num2/num3/num4;

break; }

case '*':{

cout<<"Your Multiplication Answer is : "<<num1*num2*num3*num4;

break; }

default:{

cout<<"The Operator is NOT in List, Please Enter The Correct Operator"<<endl<<endl;

goto Y;

break; }

return 0;

3
2. Write a C++ code that simulate a Driving of a manual car
a. Should indicate starting of a car

b. Should indicate change of gear from neutral to gear 1

c. Gear1 to gear2 after speed has reached 20

d. Gear2 to gear3 after speed has reached 40

e. Gear3 to gear4 after speed has reached 60

f. Should show the increase of car speed

g. Should display currently you are at what gear

h. After speed has reached 60 apply break and stop the car

i. Should indicate the car has stopped

j. Should work free of error and crushing

C++ CODE:

#include<iostream>

#include<windows.h>

using namespace std;

void start(){

char S, A;

cout<<"Press 'S' For Starting The Car"<<endl;

cin>>S;

cout<<" car is now starting. . . . ."<<endl<<endl;

Sleep(3000);

cout<<"Press 'A' For Changing Gear From NEUTRAL to GEAR_1"<<endl;

cin>>A;

cout<<endl<<"a car is changing from NEUTRAL to GEAR_1"<<endl;

Sleep(3000);

4
void speed(){

char B, C, D ;

for(int a=0;a<=60;a++){

cout<<"speed "<<a<<"km/hr"<<endl;

Sleep(1000);

if(a==20){

cout<<endl<<"Press 'C' For Changing Gear From GEAR_1 to GEAR_2"<<endl;

cin>>C;

cout<<endl<<"changed from GEAR_1 to GEAR_2"<<endl;

else if(a==40){

cout<<endl<<"Press 'D' For Changing Gear From GEAR_2 to GEAR_3"<<endl;

cin>>D;

cout<<endl<<"changed from GEAR_2 to GEAR_3"<<endl; }

else if (a==60){

cout<<endl<<"Press 'B' For Applying The BREAK"<<endl;

cin>>B;

cout<<"BREAK is applied"<<endl<<endl;

Sleep(3000);

cout<<"car is now STOPPED"; }

int main(){

cout <<"C++ CODE THAT SIMULATE A DRIVING OF A MANUAL


CAR:"<<endl<<endl;

start();

speed(); return 0; }

You might also like