Ramirez slideshow
-
Upload
janineramirez16 -
Category
Documents
-
view
411 -
download
0
Transcript of Ramirez slideshow
FUNDAMENTALS OF PROGRAMMING
Final Examination
Submitted to:
Prof. Erwin Globio
Submitted by:
Janine Rachel F. Ramirez
2011367621
For more on C++ Programs go to: http://eglobiotraining.com
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE
The switch statement body consists of a series of case labels and an optional default label. No two constant expressions in case statements can evaluate to the same value. The default label can appear only once. The labeled statements are not syntactic requirements, but the switch statement is meaningless without them. The default statement need not come at the end; it can appear anywhere in the body of the switch statement. A case or default label can only appear inside a switch statement.
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: SWITCH CASE EXAMPLE 1 char ticket; cout<<"Please choose your ticket:\n"<<endl<<"Ticket [A] - Manila to Intramuros."<<endl <<"Ticket [B] - Manila to City Hall."<<endl<<"Ticket [C] - Manila to Mall of Asia.\n"<<endl; cin>>ticket; switch (ticket) { case 'a': cout<<"\nThe price of Ticket [A] is P 15.00. Please proceed to the cashier.\n"<<endl; break; case 'b': cout<<"\nThe price of Ticket [B] is P 12.00. Please proceed to the cashier.\n"<<endl; break; case 'c': cout<<"\nThe price of Ticket [C] is P 25.00. Please proceed to the cashier.\n"<<endl; break; default: cout<<"You must choose a ticket to proceed."<<endl; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE EXAMPLE 1 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: SWITCH CASE EXAMPLE 2 char name; cout<<"Please choose a horse to bet on: Abe, Chuck or Steve."<<endl <<"Please enter a for Abe, b for Chuck and c for Steve.\n"<<endl; cin>>name; switch (name) { case 'a': cout<<"\nYou choose Abe. He has a 45% chance of winning.\n"<<endl; break; case 'b': cout<<"\nYou choose Chuck. He has a 50% chance of winning.\n"<<endl; break; case 'c': cout<<"\nYou choose Steve. He has a 75% chance of winnng. \n"<<endl; break; default: cout<<"You must choose a horse to proceed."<<endl; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE EXAMPLE 2 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: SWITCH CASE EXAMPLE 3
int equation; int x, y, z; cout<<"Please choose which arithmetic operation to use. 1 for
addition, 2 for subtraction, 3 for multiplication or 4 for division.\n"<<endl; cin>>equation; switch (equation) { case 1: cout<<"\nPlease enter two integers: "<<endl; cin>>x>>y; z=x+y; cout<<"\nTheir sum is: "<<z<<endl<<endl; break; case 2: cout<<"\nPlease enter two integers: "<<endl; cin>>x>>y; z=x-y; cout<<"Their difference is: "<<z<<endl<<endl; break;
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE EXAMPLE 3 CONTINUATION case 3: cout<<"\nPlease enter two integers: "<<endl; cin>>x>>y; z=x*y; cout<<"Their product is: "<<z<<endl<<endl; break; case 4: cout<<"\nPlease enter two integers: "<<endl; cin>>x>>y; z=x/y; cout<<"Their quotient is: "<<z<<endl<<endl; break; default: cout<<"You must choose an operation to
proceed."<<endl; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE EXAMPLE 3 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: SWITCH CASE EXAMPLE 4 int food; cout<<"Please choose your dessert.\n"<<endl<<"Menu:\n"<<"[1] Chocolate Cake\n" <<"[2] Strawberry Cake\n"<<"[3] Mango Cake\n"<<endl; cin>>food; switch (food) { case 1: cout<<"\nThe Chocolate Cake is P210.00. Please proceed to the cashier.\
n"<<endl; break; case 2: cout<<"\nThe Strawberry Case is P150.00. Please proceed to the cashier.\
n"<<endl; break; case 3: cout<<"\nThe Mango Cake is P110.00. Please proceed to the cashier.\
n"<<endl; break; default: cout<<"Please choose a cake!\n"<<endl; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE EXAMPLE 4 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: SWITCH CASE EXAMPLE 5 int dinner; cout<<"Please choose your dinner.\n"<<endl<<"Menu:\n"<<"[1] Sinigang na baboy\
n" <<"[2] Beef Steak\n"<<"[3] Chicken Curry\n"<<endl; cin>>dinner; switch (dinner) { case 1: cout<<"\nThe Sinigang na baboy is P120.00. Please proceed to the cashier.\
n"<<endl; break; case 2: cout<<"\nThe Beef Steak is P150.00. Please proceed to the counter.\n"<<endl; break; case 3: cout<<"\nThe Chicken Curry is P110.00. Please proceed to the counter.\
n"<<endl; break; default: cout<<"Please choose a cake!\n"<<endl; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
SWITCH CASE EXAMPLE 5 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
LOOPING STATEMENT
a loop is a way of repeating a statement a number of times until some way of ending the loop occurs. It might be run for a preset number of times, typically in a for loop, repeated as long as an expression is true (a while loop) or repeated until an expression becomes false in a do while loop.
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: LOOPING STATEMENT EXAMPLE 1: FOR int main() { int width, space, alignleft, count=16; for(width=1;width<=8;width++) { for (alignleft=width ; alignleft>=0 ; alignleft--) { cout<<" "; } for (space=1 ; space<count ; space++) { cout<<"*"; } cout<<endl; count=count-2; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mLOOPING STATEMENT EXAMPLE 1 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: LOOPING STATEMENT EXAMPLE 2: FOR int x; cout<<"Please enter an integer and I will
countdown beginning from the" <<endl<<"integer you input.\n"<<endl; cin>>x; cout<<endl; for (x=16; x>-1; x--) { cout<<x<<", "; } cout<<"\nThis concludes my countdown.\n"<<endl;
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mLOOPING STATEMENT EXAMPLE 2 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: LOOPING STATEMENT EXAMPLE 3: WHILE int x; cout<<"Please enter an integer and I will countdown
beginning from the" <<endl<<"integer you input.\n"<<endl; cin>>x; cout<<endl; while (x>0){ cout<<x<<", "; x--; } cout<<endl<<"\nThis concludes my countdown.\
n"<<endl;
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mLOOPING STATEMENT EXAMPLE 3 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: LOOPING STATEMENT EXAMPLE 4: WHILE
int x=4, y=3; while (x>0){ cout<<"This sentence is repeated 4
times."<<endl; x--; } while (y>0){ cout<<"While this sentence is repeated
only 3 times."<<endl; y--; }
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mLOOPING STATEMENT EXAMPLE 4 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mC++ PROGRAMMING: LOOPING STATEMENT EXAMPLE 5: DO WHILE int x, y, z; char answer; do { cout<<"Please enter two integers and I will add them."<<endl; cin>>x>>y; z=x+y; cout<<"\nThe sum of "<<x<<" and "<<y<<" is "<<z<<endl; cout<<"\nWould you like me to add another two integers? Please answer
with y for yes and n for no."<<endl; cin>>answer; cout<<endl; } while (answer=='y'); cout<<"\nGood bye!"<<endl;
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mLOOPING STATEMENT EXAMPLE 5 OUTPUT
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
m
YOU CAN FIND THIS PRESENTATION AT MY SLIDESHARE ACCOUNT AT: http://www.slideshare.net/janine_ramirez16
For m
ore
on C
++
Pro
gra
ms g
o to
: http
://e
glo
bio
train
ing.co
mThis Power Point presentation is created by:
Janine Rachel F. Ramirez
The Power Point presentation is to be submitted to:
Prof. Erwin Globio
The Official Website is:http://eglobiotraining.com/