0% found this document useful (0 votes)
51 views13 pages

2 ND PL Exercise

This document contains a project submitted by James Q. Monsanto, a student of the College of Computer Studies at Arellano University. The project contains 20 programs written in C++ covering topics like loops, functions, arrays, and basic calculations. Each program is accompanied by its corresponding output. The programs demonstrate James' understanding of programming concepts and C++ syntax.

Uploaded by

James Monsanto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views13 pages

2 ND PL Exercise

This document contains a project submitted by James Q. Monsanto, a student of the College of Computer Studies at Arellano University. The project contains 20 programs written in C++ covering topics like loops, functions, arrays, and basic calculations. Each program is accompanied by its corresponding output. The programs demonstrate James' understanding of programming concepts and C++ syntax.

Uploaded by

James Monsanto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

Arellano University

2600 Legarda St., Sampaloc M.M


College of Computer Studies

Project
In
Programming
Languages
S.Y. 2015-2016
Submitted by:
James Q. Monsanto
BSCS-IT-2C
Submitted to:
Prof. Gina Clemente

11. Sum (while loop)


#include <iostream.h>
#include <conio.h>
main(){
clrscr ();
int n;
cout<<"\nInput Value: ";
cin>>n;
int counter =1;
int sum=0;
while (counter <=n)
{
sum=sum+counter;
counter++;
}
cout<<"The sum is: "<<sum;
getch ();
return 0;
}

Output:

12. Factorial Number (loop)


#include <iostream.h>
#include<conio.h>
#include<stdlib.h>
int main() {
clrscr();
int i, n, factorial = 1;
cout<<"Input a value: ";
cin>>n;
for (i = 1; i <= n; ++i) {
factorial *= i;}
cout<< "Factorial of "<<n<<" is "<<factorial;
getch();
return 0;
}

Output:

13. Numbers (do-while loop)


#include<iostream.h>
#include<conio.h>
main()
{
clrscr ();
int n=0;
int result=1;
cout<<"\nNumbers are: ";
do{
result+=n;
cout<<result<<",";
n++;

}while(n<=10)
;
int k;
cin>>k;
getch ();
return 0;
}

Output:

14. Fibonacci
#include<iostream.h>
#include<conio.h>
class fib
{
public:
int a,b,c;
void generator(int);
};
void fib::generator(int n)
{
a=1,b=1;
cout<<a<<" "<<b;
for(int i=1;i<=n-2;i++)
{
c=a+b;
cout<<" "<<c;
a=b;
b=c;
}
}
void main()
{

clrscr();
int n;
cout<<"Enter number of terms you need in the series: ";
cin>>n;
fib ob;
ob.generator(n);
getch();
}

Output:

15. Cell Phone Pin


#include <iostream.h>
#include<conio.h>
main ()
{
clrscr();
int ctr = 0, ctr1 = 0;
int pin, puk;
do{
cout << "Enter pin code: ";
cin >> pin;
if (pin == 0123)
{
cout << "Welcome to SGS Telecom" << endl;
ctr = 3;
getch();
return 0;
}
else
{
cout << "Invalid Pin Code" << endl;
ctr+=1;
}

}while (ctr !=3)


if (ctr = 3){
do{
cout << "Enter PUK code: ";
cin >> puk;
if (puk == 1234)
{
cout << "Welcome to SGS Telecom" << endl;
ctr1=3;
getch ();
return 0;
}
else{
cout << "Invalid PUK Code" << endl;
ctr1+=1;
}
}while (ctr1 !=3);
}
if (ctr1 = 3)
{
cout << "SIM BLOCKED" << endl;
}
getch();
return 0;
}

Output:

16. Presidential Elections


#include<iostream.h>
#include<conio.h>
int main(){
clrscr ();
char choice,choice2;
int ca=0,cb=0,cc=0,tv=0;
do{
cout<<"\t PRESIDENTIAL ELECTIONS";
cout

<<"\n

Candidate\n";

cout<<"<A>Grace Poe\n<B>Jejomar Binay\n<C>Rodrigo Duterte\n";


cout<<"-----------------------\n";
cout<<"Enter <V>-vote <R>-result and <Q>-quit : ";
cin>>choice2;
if (choice2=='V')
{

cout<<"Enter your vote: ";

cin>>choice;
switch(choice){
case 'A':
case 'a':
ca++;
break;
case 'B':
case 'b':
cb++;
break;
case 'C':
case 'c':
cc++;
break;}
}
else if (choice2=='R'){
cout<<"\t Presidential Elections\n\n";
cout<<"Candidates:"<<"\t

Results:"<<"\n\n";

cout<<"<A>Grace Poe: "


cout<<"<B>Jejomar Binay: "

<<ca<<"\n";
<<cb<<"\n";

cout<<"<C>Rodrigo Duterte: " <<cc<<"\n\n";


tv=ca+cb+cc;
cout<<"TOTAL VOTES: "<<tv<<"\n";
if((ca>cb)&&(ca>cc)){
cout<<"\nGrace Poe is the Winner";}
else if((cb>ca)&&(cb>cc)){
cout<<"\nJejomar Binay is the Winner";}
else if((cc>ca)&&(cc>cb)){
cout<<"\nRodrigo Duterte is the Winner";}}}
while (choice2 !='Q');
return 0;
}

Output:

17. Grades (Passed-Failed)


#include<iostream.h>
#include<conio.h>
main(){
clrscr ();
int passed=0, failed=0, grade;
for(int i=1; i<11; i++){
cout<<"Grade # "<<i<<" ";
cin>>grade;
if(grade<75)
failed++;
else
passed++;
}
cout<<endl<<"Total passed: "<<passed;
cout<<endl<<"Total failed: "<<failed;
cout<<endl;
getch ();
return 0;
}

Output:

18. Number-Asterisk
A.
#include<iostream.h>
#include<conio.h>
void main(){
int i,j;

Output:

clrscr();
for(i=1 ; i<=5 ; i++){
for(j=0 ; j<=9 ; j++){
cout<<j;}
cout<<endl;}
getch();
}

B.
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1; i<=6; i++){
for(j=1; j<i; j++){
cout<<"*";
}
cout<<"\n";
}
getch();
}

C.

Output:

#include <iostream.h>
#include<conio.h>
main(){
int i,j;
clrscr();
for(i=5;i>=1;--i){
for(j=1;j<=i;++j){
cout<<j<<" ";
}
cout<<"\n";
}
getch ():
return 0;
}

19. Multiplication Table


#include<iostream.h>
#include<conio.h>
main(){
clrscr();
int col, row;
cout<<"Input no. of row(s): ";
cin>>row;
cout<<"\nInput no. of column(s): ";
cin>>col;
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
cout<<i*j<<" ";
}

cout<<endl;
}

Output:

getch ();
return 0;
}

Output:

20. Simple Calculator


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int num1, num2;
char selection;
double sum,difference,product,quotient;
cout<< "\nFirst Number: ";
cin>> num1;
cout<< "Second Number: ";
cin>> num2;
cout<< "\n";
cout<< "

MENU\n";

cout<< "(+) Addition\n";


cout<< "(-) Subtraction\n";
cout<< "(*) Multiplication\n";
cout<< "(/) Division\n";
cout<< "Enter Choice: ";
cin>>selection;
switch(selection){

case '+':
sum = num1+num2;
cout<<"\nThe answer is:"<<sum<<endl;
break;
case '-':
difference = num1-num2;
cout<<"\nThe answer is: "<<difference<<endl;
break;
case '*':
product = num1*num2;
cout<<"\nThe answer is: "<<product<<endl;
break;
case '/':
quotient = num1/num2;
cout<<"\nThe answer is: "<<quotient<<endl;
}
getch ();
return 0;
}

Output:

You might also like