fibonacci series, reverse digit, parking lot program, calculator using c++

6
Page one contain fibioancci series,page 2 cointain reverse digit Page 3 cointain parking lot program Page 4 and 5 contain calculator // Create a program which generates Fibonacci series for the first 'n' numbers where 'n' is entered by the user. For e.g. if the user enters 6 then the output would be: 1 1 2 3 5 8. #include<iostream>//header files using namespace std;//string void main()//leaves screen void { int numA = 0;//define first fibonacci series numbers int numB = 1;//define two fibonacci series numbers int numC;//declare the variable to store the next number of fibonacci series int i;//the counter to keep track how many numbers are printed. int n=2;//declare the variable to store how many numbers to be printed. Default is 2 cout<<"How many Fibonacci number you need ? : " ;//Ask user how many numbers of the fibonacci series need to be printed cin>>n;//input stored in n for (i = 1; i <= n; i++)//for loop to calculate the new element of the series and printing the same { numC = numB;//arthimathic equation numB += numA;//arthimathic equation numA = numC;//arthimathic equation cout << "\t" << numC; //output obtained with giving distance of tabs } system("pause");//pauses the system screen }

Upload: buitems

Post on 22-May-2015

1.604 views

Category:

Education


4 download

DESCRIPTION

Page one contain fibioancci series,page 2 cointain reverse digit Page 3 cointain parking lot program Page 4 and 5 contain calculator

TRANSCRIPT

Page 1: Fibonacci series, reverse digit, parking lot program, calculator using C++

Page one contain fibioancci series,page 2 cointain reverse digit

Page 3 cointain parking lot programPage 4 and 5 contain calculator

// Create a program which generates Fibonacci series for the first 'n' numbers where 'n' is entered by the user. For e.g. if the user enters 6 then the output would be: 1 1 2 3 5 8.

#include<iostream>//header filesusing namespace std;//stringvoid main()//leaves screen void{ int numA = 0;//define first fibonacci series numbers int numB = 1;//define two fibonacci series numbers int numC;//declare the variable to store the next number of fibonacci series int i;//the counter to keep track how many numbers are printed. int n=2;//declare the variable to store how many numbers to be printed. Default is 2 cout<<"How many Fibonacci number you need ? : " ;//Ask user how many numbers of the fibonacci series need to be printed cin>>n;//input stored in n for (i = 1; i <= n; i++)//for loop to calculate the new element of the series and printing the same {

numC = numB;//arthimathic equation numB += numA;//arthimathic equation numA = numC;//arthimathic equation

cout << "\t" << numC; //output obtained with giving distance of tabs } system("pause");//pauses the system screen }

Page 2: Fibonacci series, reverse digit, parking lot program, calculator using C++

//A program which reverses the numerals in an integer, that is 326 becomes 623, etc. (Note: Input should be greater than 10 and less than 1000)#include<iostream>i//ostream is a header file which is used for input/output in the C++ programming language using namespace std;//stringvoid main()//leaves vaccant space on screen{

int x,a,b,c;// integers taken,x for input the digit to reverse.....a ,b for consistant calculations....c is used for final calculations

char p;//used for switchchar n;//null charactercout<<"Select The Following \n Press 1 To Reverse 2 Digit

Number \n Press 2 To Reverse 3 Digit Number\n \n";//used to create a menu swtyle

cin>>p;//input stored in p charcterswitch (p)//switch used to control statements{case '1': //condition 1 providedcout<<"enter a number which you want to reverse=\n" ;//output

provided cin>>x;//input stored in x to reverse a=x/10; // a is obtained by dividing number to reverse by 10 b=x%10; // b is obtained by multiplying x with percentage 10 c=(b*10)+a;// c is obtained by multiplying b with ten and then adding it to a cout<<c;//answer is obtained

cin>>n;//null input to stop screenbreak;//switch breaker

case '2'://same as case 1 cout<<"enter a number which you want to reverse=\n" ; cin>>x;

a = x/100; b = x%10; c= x - 99* (a - b);

cout<<"the reverse is=\n"; cout<<c;

cin>>n;break;default:

system("pause");//system paused}

Page 3: Fibonacci series, reverse digit, parking lot program, calculator using C++

}

//program that, given the type of vehicle (‘c’ for car, ‘b’ for bus; ‘t’ for truck)//and the hours a vehicle spent in the parking lot,//determines the parking charge based on the rates shown below:

//Car..........Rs. 20 per hour//Bus..........Rs. 30 per hour//Truck.......Rs. 40 per hour #include <iostream> //iostream is a header file which is used for input/output in the C++ programming language using namespace std; //stringvoid main() //leaves vaccant space on screen{int y,s;//two integers y=time consumed,s=sumchar b;//character b is used to initialize character in the outputchar x;//null character used to keep the screen intact

cout << "Time Consumed By The Car In Parking Lot: ";//for output display on screencin >> y;//value stored in ycout << "You Entered: " << y << endl << endl;//for output display on screen

cout << "Enter Vehicle Type By Entering Symbol Instead of Bus,Truck,and Car(b,t,c): ";//for output display on screencin >> b;//value stored in bcout << "You Entered: " << b << endl << endl;//for output display on screen

switch (b)//the switch statement provides a convenient alternative to

the if when dealing with a multi-way branch { case 'c': //condition provided

s=y*20;//arthimathic formulacout << "Charges: " << endl << endl;//for output display on screencout<<s;//for output display on screencin>>x;//input stored in a variablebreak;//used to break the switch case 't'://case used

s=y*40;//arthimathic formulacout << "Charges: " << endl << endl;//for output display on screencout<<s;//for output display on screencin>>x;//input stored in a variablebreak;//used to break the switch case 'b'://case useds=y*30;//arthimathic formulacout << "Charges: " << endl << endl;//for output display on screencout<<s;//for output display on screencin>>x;//input stored in a variablebreak;//used to break the switch default://gives the default value

Page 4: Fibonacci series, reverse digit, parking lot program, calculator using C++

system("pause");//pauses the system}

}

//A realistic program: Desk Calculator#include<iostream>//header files

using namespace std;//string

void main()//leaves screen void

{

int a,b,f;// integers

char m,x;//characters

int s=0;// initiates value of s to zero

cout<<"enter Digit 1:";//takes output

cin>>a;//input value stored in a

cout<<"enter Digit 2:";//output given

cin>>b;//input stored in b

cout<<"enter operator:";// output provided

cin>>m;//input stored in m

if (m=='+')//nested statements used to calculate solution

s=a+b;

if(m=='-')

s=a-b;

if(m=='*')

Page 5: Fibonacci series, reverse digit, parking lot program, calculator using C++

s=a*b;

if(m=='/')

s=a/b;

//statements with arthimathic formula

cout<<"your current solution is:";//output answer

cout<<s<<endl;

cout<<"press a to continue or press c to clear:";

cin>>x;

while(x!='c'){//while continuty used

cout<<"new operator with which you want to continue:";

cin>>m;

cout<<"new new number with which you want perform arthemathic calculations:";

cin>>f;

if (m=='+')//nested statements used to calculate solution

s=f+s;

if (m=='-')

s=s-f;

if (m=='*')

s=s*f;

if(m=='/')

s=s/f;//statements with arthimathic formula

cout<<"your current solution is";//output answer

cout<<s<<endl;

}

Page 6: Fibonacci series, reverse digit, parking lot program, calculator using C++

system("pause");//system pause

}