project in programming

Post on 18-Nov-2014

551 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

My final project for programming :)

TRANSCRIPT

http://eglobiotraining.com/

PROJECT IN PROGRAMMING

Submitted by: Ken M. Sahashi

BM10203

http://eglobiotraining.com/

SWITCH STATEMENTS

#include <iostream>#include <cstdio>using namespace std;int main(){int number;cout<< "Enter a number between

1 and 5: ";cin>> number;switch (number){case 0: cout<< "Too small,

sorry!";break;case 5: cout<< "Good job!\n"; break;case 4: cout<< "Nice Pick!\n"; break;

case 3: cout<< "Excellent!\n"; break;case 2: cout<< "Masterful!\n"; break;case 1: cout<< "Incredible!\n";break;default: cout<< "Too large!\n";}cout<< "\n\n";system ("pause");return 0;}

http://eglobiotraining.com/

SAMPLE OUTPUT

http://eglobiotraining.com/

This programming accepts a number between 1 and 5 . If the user enters a right number the programming will show an output according to its number.

http://eglobiotraining.com/

#include <iostream>#include <cstdio>using namespace std;int main(){intch, len , wid , area , per ;balik:system ("cls");cout<< " ***** Area - Perimeter

Program ******* "<<endl<<"\t\t(Rectangle)"<<endl;

cout<< "\n [1] Area \n [2] Perimeter \n\n\n\n\n " <<endl;

cout<< "Enter your choice here : " ;

cin>>ch;cout<< " Enter the length : ";cin>>len;

cout<< " Enter the width : ";cin>>wid;area=len*wid;per=(2*len)+(2*wid);switch (ch){case 1 : cout<< " The Area is : "

<< area <<endl;break;case 2 : cout<< " The perimeter is

: " <<per<<endl;break;default: gotobalik;} system ("pause");return 0;}

http://eglobiotraining.com/

SAMPLE OUTPUT

http://eglobiotraining.com/

This programming computes for the area or perimeter of a given rectangle given that the user will input its length and width. After the programming accepts the values for dimensions of the rectangle, the programming lets the user choose if the programming will compute for its perimeter or area. Then the programming will compute for whatever the user chose and then prints the computed value. Lastly the programming will ask the user to press any key to end the programming.

http://eglobiotraining.com/

#include "iostream"using namespace std;int main (){ int rem , x;balik:system ("cls");cout << "[1] January "<<endl;;cout << "[2] February "<<endl;cout << "[3] March "<<endl;cout << "[4] April "<<endl;cout << "[5] May "<<endl;cout << "[6] June "<<endl;cout << "[7] July "<<endl;cout << "[8] August "<<endl;cout << "[9] September "<<endl;cout << "[10] October "<<endl;cout << "[11] November "<<endl;cout << "[12] December "<<endl<<endl;

cout << "Enter the number of month : ";cin >> x;

switch (x){case 1: cout<< "Your birthstone is Garnet "<<endl;break;case 2: cout<< "Your birthstone is Amethyst "<<endl;break;case 3: cout<< "Your birthstone is Aquamarine "<<endl;break;case 4: cout<< "Your birthstone is Diamond "<<endl;break;case 5: cout<< "Your birthstone is Shamrock "<<endl;break;case 6: cout<< "Your birthstone is Alexandrite "<<endl;break;case 7: cout<< "Your birthstone is Ruby "<<

http://eglobiotraining.com/

Amethyst "<<endl;break;case 3: cout<< "Your birthstone is Aquamarine "<<endl;break;case 4: cout<< "Your birthstone is Diamond "<<endl;break;case 5: cout<< "Your birthstone is Shamrock "<<endl;break;case 6: cout<< "Your birthstone is Alexandrite "<<endl;break;case 7: cout<< "Your birthstone is Ruby "<<endl;break;case 8: cout<< "Your birthstone is Peridot "<<endl;break;case 9: cout<< "Your birthstone is Sapphire "<<endl;break;case 10: cout<< "Your birthstone is Rose Zircon "<<endl;break;case 11: cout<< "Your birthstone is Topaz "<<endl;break;case 12: cout<< "Your birthstone is Blue Zircon "<<endl;break;default:system ("cls"); cout<< "Invalid Input!!"<<endl;goto balik;break;}

system ("pause");return 0;}

http://eglobiotraining.com/

http://eglobiotraining.com/

This programming will display the equivalent birthstone of each month using switch statement.

http://eglobiotraining.com/

#include "iostream.h"using namespace std;int main (){

system ("cls");for (int x = 1 ; x <= 10 ; x++ ){

switch ( x ){

case 1: cout<< " One "<<endl;break;case 2: cout<< " two "<<endl;break;case 3: cout<< " three"<<endl;break;case 4: cout<< " four "<<endl;break;case 5: cout<< " five "<<endl;break;case 6: cout<< " six "<<endl;break;case 7: cout<< " seven "<<endl;break;case 8: cout<< " eight "<<endl;break;case 9: cout<< " nine "<<endl;break;default: cout<< " ten "<<endl;break;

}

system ("pause");return 0;

}

http://eglobiotraining.com/

http://eglobiotraining.com/

This programming allows the user to input a number from 1 to 10. If the user input a right number,the programming will run correctly and it will display the equivalent of the number in words.

http://eglobiotraining.com/

#include "iostream.h"using namespace std;int main (){ int rem , x;

system ("cls")cout << "Enter an integer : ";cin >> x;rem=x%2;

switch (rem){case 1: cout<< " Odd "<<endl;break;default: cout<< " even "<<endl;break;}

system ("pause");return 0;

}

http://eglobiotraining.com/

http://eglobiotraining.com/

This programming allows the user to enter a integer number in which it will also display if it is even or odd after executing the indicated operation in the programming. We all know that the number is even if it’s remainder is 0 and odd if it’s remainder is 1.

http://eglobiotraining.com/

ITERATION/LOOPING STATEMENTS1. FOR LOOP

#include <iostream>#include <conio.h>using namespace std;int main(){intnum, ctr=2, fact=0;system ("cls");cout<<"Enter a number: ";cin>>num;{for (;ctr<num;ctr++){if(num%ctr==0)

fact+=1;}}if(fact>0)cout<<"COMPOSITE!";elsecout<<"PRIME!";}cout<< "\n";system ("pause");return 0;}

http://eglobiotraining.com/

SAMPLE OUTPUT

http://eglobiotraining.com/

This programming allows the user to input a number. This number will be test if it’s a PRIME or COMPOSITE.

http://eglobiotraining.com/

#include "iostream.h"using namespace std;int main (){

system ("cls");for (int x = 1 ; x <= 10 ; x++ )cout << x << "\t" << x*x<< endl;system ("pause");return 0;

}

http://eglobiotraining.com/

SAMPLE OUTPUT

http://eglobiotraining.com/

In this programming,the user is allowed to enter a number from 1 to 10 and once he/she enters the number the programming will execute the operation in which it will displays the square of the number inputted by the user.

http://eglobiotraining.com/

#include "iostream.h"using namespace std;int main (){

system ("cls");for (int x = 1 ; x <= 10 ; x++ )

{for( y=1 ; <=10 ; y++){cout <<"#"<< endl;

}cout << "\t";

}system ("pause");return 0;

}

http://eglobiotraining.com/

http://eglobiotraining.com/

This programming draw a ten by ten sharp symbol box using the for loop.

http://eglobiotraining.com/

DO WHILE

 #include <iostream>using namespace std;int main(){ intdec;charch;do {system ("cls");cout<< "Enter a decimal:

";cin>>dec;cout<< " THe number in

Octal is : " <<oct<<dec<<endl<<endl;

cout<< "Do you wish to try again [Y/N]? : ";

cin>>ch;}while (toupper(ch)==

'Y');system ("pause");return 0;}

http://eglobiotraining.com/

SAMPLE OUTPUT

http://eglobiotraining.com/

This programming converts the user’s input of decimal number system into octal number system. The first step in this programming is to ask the user to input an integer of base 10(decimal). Next, the programming will compute the value of the base 10 into base 8 or octal number system. After the programming has computed the value of base 10 integer to octal, now it will output or print the answer of conversion of decimal to octal. Then the programming will ask the user if he/she wants to try again. The programming accepts only Y for yes and N for a no. Lastly the programming asks the user to press any key to end the programming.

http://eglobiotraining.com/

WHILE

#include "iostream"#include "conio.h"using namespace std;int main (){charch = 'a';system ("cls");while (ch !='q') {cin>>ch;

}cout<< "Trip

Executed !!! "<<endl<<endl;

system ("pause");return 0;}

 

http://eglobiotraining.com/

SAMPLE OUTPUT

http://eglobiotraining.com/

This programming accepts any character such as alphanumeric and special characters(symbols and the like). After the input of the user, the programming will now test the entered character. If the programming reads the letter q or Q the programming will end and outputs “PROGRAM EXECUTED”.

http://eglobiotraining.com/

This powerpoint is saved at http://www.slideshare.net/

This project is submitted to:Prof. Erwin Globiohttp://eglobiotraining.com/

top related