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

  • 1,473 views
Uploaded on

Page one contain fibioancci series,page 2 cointain reverse digit …

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

More in: Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,473
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 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 thefirst n numbers where n is entered by the user. For e.g. ifthe 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 offibonacci series int i;//the counter to keep track how many numbers areprinted. int n=2;//declare the variable to store how many numbers tobe printed. Default is 2 cout<<"How many Fibonacci number you need ? : " ;//Ask userhow 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 newelement 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 givingdistance of tabs } system("pause");//pauses the system screen }
  • 2. //A program which reverses the numerals in an integer, that is 326becomes 623, etc. (Note: Input should be greater than 10 and less than1000)#include<iostream>i//ostream is a header file which is used forinput/output in the C++ programming languageusing namespace std;//stringvoid main()//leaves vaccant space on screen{ int x,a,b,c;// integers taken,x for input the digit toreverse.....a ,b for consistant calculations....c is used for finalcalculations char p;//used for switch char n;//null character cout<<"Select The Following n Press 1 To Reverse 2 Digit Numbern Press 2 To Reverse 3 Digit Numbern n";//used to create a menuswtyle cin>>p;//input stored in p charcter switch (p)//switch used to control statements { case 1: //condition 1 provided cout<<"enter a number which you want to reverse=n" ;//outputprovided 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 thenadding it to a cout<<c;//answer is obtained cin>>n;//null input to stop screen break;//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}}
  • 3. //program that, given the type of vehicle (‘c’ for car, ‘b’ for bus; ‘t’ fortruck)//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 forinput/output in the C++ programming languageusing 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 intactcout << "Time Consumed By The Car In Parking Lot: ";//for output display onscreencin >> y;//value stored in ycout << "You Entered: " << y << endl << endl;//for output display on screencout << "Enter Vehicle Type By Entering Symbol Instead of Bus,Truck,andCar(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 tothe if when dealing with a multi-way branch { case c: //condition provideds=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 useds=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 system("pause");//pauses the system
  • 4. }}//A realistic program: Desk Calculator#include<iostream>//header filesusing namespace std;//stringvoid main()//leaves screen void{int a,b,f;// integerschar m,x;//charactersint s=0;// initiates value of s to zerocout<<"enter Digit 1:";//takes outputcin>>a;//input value stored in acout<<"enter Digit 2:";//output givencin>>b;//input stored in bcout<<"enter operator:";// output providedcin>>m;//input stored in mif (m==+)//nested statements used to calculate solutions=a+b;if(m==-)s=a-b;if(m==*)
  • 5. s=a*b;if(m==/)s=a/b;//statements with arthimathic formulacout<<"your current solution is:";//output answercout<<s<<endl;cout<<"press a to continue or press c to clear:";cin>>x;while(x!=c){//while continuty usedcout<<"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 solutions=f+s;if (m==-)s=s-f;if (m==*)s=s*f;if(m==/)s=s/f;//statements with arthimathic formulacout<<"your current solution is";//output answercout<<s<<endl;}
  • 6. system("pause");//system pause}