You are on page 1of 27

CSC128

CSC 128
Fundamental OF
FUNDAMENTAL Of COMPUTER
Computer
Problem Solving
PROBLEM SOLVING

PAST EXAM
PAST YEAR

BY: Ahmad Adam bin Adnan


By: Muhammad Nizam bin Yusuf
GROUP : CS110ID Num: 2015506461
Student
LECTURER
Date : 2:ndKhairunnisa
March 2016bt Abdul Kadir

TASK A (1)
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char fifa[35];
char t[35]="Ola Bola 2014 FIFA World Cup.";

strcpy(fifa,t);
cout<<fifa<<endl<<endl;
}

TASK A-1

2
TASK A (2)
#include<iostream>
using namespace std;
int main()
{
int evenNum=0, counter=0,num=1;

while(counter<10)
{ if(num%2==0)
evenNum=evenNum+1;
counter++;
num=num+1; }

cout<<evenNum<<"\n\n";
}

TASK A-2

3
TASK C
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float result;
int num1 , num2 , o;
cout <<" Enter 2 number : ";
cin >> num1 >> num2;
cout << " Please enter your operation 1 or 2 : ";
cin >> o;

switch(o)
{ case1:
result=pow(num1,num2);
break;

case2:
result=num1%num2;
break;

default:
cout<< " Wrong operation "<<endl;
break; }

cout << " The result is :"<<result<<endl;


}

4
TASK C

5
TASK D
#include<iostream>
using namespace std;
int main()
{
char code;
cout<< "aEnter code whether a or b: ";
cin >> code;
if((code=='a') || (code=='A'))
{ cout<<"\nI am from faculty of Arts and Design";
cout<<"\n10% obtained ANC id our aim "; }
else
if((code=='b')||(code=='B'))
{ cout<<"\n I am from faculty of ";
cout<<"Business Management";
cout<<"\n 12% obtained ANC is our aim"; }
else
cout<<"\nWrong code Entered";
}

TASK D

6
TASK E
#include<iostream>
using namespace std;
int main()
{
int num,a,b;
char char1;
cout<<"Enter a number : ";
cin>>num;
cout<<"Enter a character : ";
cin>>char1;

for(a=1;a<=num;a++)
{ for(b=1;b<=a;b++)
{ if(b<=num)
cout<<char1;}
cout<<endl;}
}

TASK E

7
TASK F
#include<iostream>
using namespace std;
int main()
{
int counter=0, weight, total=0;

while(counter<10)
{ cout << "Please enter your weight : ";
cin>>weight;
if(weight>75)
total=total+1;
counter++; }
cout << " Number of student whose weight more than 75 kg is : " <<total<<"\n\n";

TASK F

8
TASK G
#include <iostream>
using namespace std;
int main()
{
char char1;
string id ;
int dest;
double adult , child , sum1 , sum2 , total , totalall , tax ;
cout<<"SEPTEMBER Promotion 2013 [from September 10-30]"<<endl;
cout<<"=============================================\n\n";
cout<<" 1. KL Bali\n";
cout<<" 2. KL Perth\n";
cout<<" 3. Kuching Singapore\n";
cout<<" 4. Kuching Beijing\n";
cout<<"=============================================\n\n" ;
cout<<"Please insert booking id: ";
cin>>id;
cout<<"Please insert destination: ";
cin>>dest;
cout<<"Please insert number of adult passengers: ";
cin>>adult;
cout<<"Please insert number of children passengers (less than 9 years old): ";
cin>>child;

if(dest==1)
{ sum1=(adult)*105;
sum2=(child)*50;
total=sum1+sum2;}

else if(dest==2)
{ sum1=(adult)*250;
sum2=(child)*78;
total=sum1+sum2;}

9
else if(dest==3)
{ sum1=(adult)*59;
sum2=(child)*29;
total=sum1+sum2;}

else if(dest==4)
{ sum1=(adult)*199;
sum2=(child)*109;
total=sum1+sum2; }
else
cout<<"wrong input";

tax=(15/100)*total;
totalall=tax+total;

while(char1!='N'||char1!='n')
{ cout<<"Booking Information"<<endl;
cout<<"==================="<<endl<<endl;
cout<<"Booking ID : "<<id<<endl<<endl;

cout<<"Destination : ";
if(dest==1)
cout<<"KL - Bali"<<endl;
else
if(dest==2)
cout<<"KL - Perth"<<endl;
else
if(dest==3)
cout<<"Kuching - Singapore"<<endl;
else
cout<<"Kuching - Beijing"<<endl;
cout<<"Number of adults :"<<adult<<endl;
cout<<"Number of children :"<<child<<\n\n;
cout<<"Total Fare : RM "<<total<<\n;
cout<<"Tax : RM"<<tax<<\n;
cout<<"Fare after tax : RM"<<totalall<<\n\n;
cout<<"Enter 'N' or 'n' to terminate\n";
cin>>char1; }}

10
TASK G

11
TASK 1(a)
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout<<"Please enter 2 number : ";
cin>>num1>>num2;
if (num1 < num2)
{cout<<endl<<" Sequential of numbers between"<<num1<<" and "<<num2<<" :-
\n"<<endl<<"\t";
while (num1 <= num2)
{cout<<num1<<"\t";
num1++;}
cout<<"\n\n";}
else
{cout<<endl<<" Sequential of numbers in reverse order between "<<num2<<" and "<<num1<<" :-
\n"<<endl<<"\t";
while (num2 <= num1)
{cout<<num1<<"\t";
num1--;}
cout<<"\n\n";}
}

TASK 1(a)
TASK 1(b)
#include <iostream>
using namespace std;
int main()
{
int counter=10;
cout<<"\n\n\t START... Press <Enter>";
cin.get() ;

while (counter >= 1)


{cout<<"\n\n\n\n\n\n\n\n\t\t\t"<<" \t "<<counter;
cin.get();
counter--; }

cout<<"\n\n\n\n\n\t KAABOOOOOMM!!";
cin.get();
}

TASK 1(b)
TASK 2(a)
#include <iostream>
using namespace std;
int main()

int num;
cout<<"Enter integer number (negative number to quit) : ";
cin>>num;
while (num >=0)
{cout<<"Number you entered is : "<<num<<endl;
cout<<"Enter interger number (negative number to quit) : ";
cin>>num;}
cout<<"\nYou entered a negative number. \nBye- bye"<<endl;
}

TASK 2(a)
TASK 2(b)
#include <iostream>
using namespace std;
int main()

{
int num, sumOdd=0;
cout<<"Enter integer number (999 to quit) : ";
cin>>num;
while (num != 999)
{ if (num%2 !=0)
{sumOdd = sumOdd + num;}
cout<<"Enter positive integer number (999 to quit) : ";
cin>>num;}
cout<<"The total odd numbers are : "<<sumOdd;

TASK 2(b)
TASK 3
#include <iostream>
using namespace std;
int main()

int num;
cout<<"Enter the starting number : ";
cin>>num;
while (num >0 )
{ if (num>0)
cout<<num<<" , ";
num = num-1;}

cout<<"FIRE!!";
}

TASK 3
TASK 4
#include <iostream>
using namespace std;
int main()
{
double quantity, priceitem, customer, total, totalprice=0;
cout<<"Enter quantity of items bought (-1 to exit) : ";
cin>>quantity;
while (quantity != -1)
{cout<<"Enter the item's price : ";
cin>>priceitem;
cout<<"Input number of customer : ";
cin>>customer;
total = totalprice + (quantity*priceitem);
customer++;
cout<<"\nEnter quantity to exit (-1 to exit) : ";
cin>>quantity;}

cout<<"Total amount paid by all customer : "<<total;


}

TASK 4
TASK 5
#include <iostream>
using namespace std;
int main()
{

char gender;
int student=0, counter=0, total=0;
while (counter <10 )
{cout<<"Input gender 'F' for female || 'M' for male : ";
cin>>gender;
if (gender == 'F' || gender == 'f')
{student++;}
else
if (gender == 'M' || gender== 'm')
{cout<<"Sorry, Female only\n";}
counter++;}
cout<<"\nTotal number of female student is : "<<student<<endl;
}

TASK 5
TASK 1
#include <iostream>
using namespace std;
float calcTotalSales(float, int);
float calcCommission(float, int, float);
void TotalCommission(float, float);
float pricePerBook = 45.40;
int main()
{
int quantity;
float commission,totalSales;
cout<<"Please enter the quantity of book you sold : ";
cin>>quantity;

totalSales=calcTotalSales(pricePerBook, quantity);
commission=calcCommission(pricePerBook, quantity,0.02);
TotalCommission(totalSales, commission);
cout<<"Thank You.\n";
}

float calcTotalSales(float pricePerBook, int quantity)


{ float total;
total=quantity*pricePerBook;
return total; }

float calcCommission(float pricePerBook, int quantity, float comRate)


{ float commission;
commission=(quantity*pricePerBook)*comRate;
return commission; }

void TotalCommission(float TotalSales,float commission)


{ cout<<"Total Sales is : RM"<<TotalSales<<endl;
cout<<"Total Commission is : RM"<<commission<<endl; }

2

TASK 1

3

TASK 2
#include <iostream>
using namespace std;
//function prototype
void mainMenu ();
void Add (int, int);
void Sub (int, int);
void displayRes(int);

int main ()
{ int x,y, choice;
cout<<"Please enter two numbers 1 : ";
cin>>x>>y;
mainMenu();
cout<<"Mathematical Operation : \n";
cout<<" 1. Addition\n 2.Substraction \n";
cout<<"Please enter your choice : ";
cin>>choice;
if (choice==1)
Add (x,y); //function call
else if (choice==2)
Sub (x,y); //function call
else
cout<<"Wrong choice! \n"; }

//function definition
void mainMenu()
{}
void Add (int a, int b)
{ //code for addition
int r;
r=a+b;
displayRes(r); }

4

void Sub (int a, int b)
{ //code for substraction
int r;
r=a-b;
displayRes(r);}

void displayRes (int res)


{ cout<<"The answer is : "<<res<<endl; }

TASK 2

5

TASK 3
#include <iostream>
using namespace std;
void calculateTotal(char code, int quantity);
void printCheck();
int main()
{
char code;
int quantity;
cout<<"Welcome To ABC Restaurant\n";
cout<<"---------------------------------------\n\n";
cout<<"Menu : 'A' ~ Muffin : RM1.20/unit\n";
cout<<"Menu : 'B' ~ Egg Sandwich : RM1.50/unit\n";
cout<<"Menu : 'C' ~ Ginger Bread : RM2.00/unit\n\n";
cout<<"Please Choose a menu : ";
cin>>code;
cout<<"Quantity you would like to buy : ";
cin>>quantity;
cout<<"\n";
calculateTotal(code, quantity);
printCheck();
}
void calculateTotal(char code, int quantity)

{
float total;
if (code=='A' || code=='a')
{ cout<<"You choosed menu with : "<<quantity<<" Muffin\n";
total=quantity*1.20; }

else
if (code=='B' || code=='b')
{ cout<<"You choosed menu with : "<<quantity<<" Egg Sandwich\n";
total=quantity*1.50; }

6

else
if (code=='C' || code=='c')
{ cout<<"You choosed menu with : "<<quantity<<" Ginger Bread\n";
total=quantity*2.00; }

else
{ cout<<"Menu is not available ! \n\n"; }
}

void printCheck()
{
float total;
cout<<"Total price is = RM "<<total<<"\n\n";
}

TASK 3

7

TASK 4
#include<iostream>
using namespace std;
float outPatientCharge(char);
float WardedPatientCharge(char,char,int);
int main()
{
char patient,wardtype;
int days,charge;
cout<<"Enter type of patient ('O' = Outpatient | 'W' = Warderd Patient) [S =
exit] : ";
cin>>patient;
while(patient!='S' || patient!='s')
{ if(patient=='O' || patient=='o')
{ charge=outPatientCharge(patient); }
else
if(patient=='W' || patient=='w')
{ cout<<"Enter Warded Patient type ('N' = Normal | 'M' Mild | 'S' = Serious) :
";
cin>>wardtype;
cout<<"Enter number of days : ";
cin>>days;
cout<<"\n";
charge=WardedPatientCharge(patient,wardtype,days); }

else
{ cout<<"Invalid type of patient !"<<"\n"; }
cout<<"Enter type of patient ('O' = Outpatient || 'W' = Warderd patient) [S =
exit] : ";
cin>>patient; }
}
float outPatientCharge(char patient)
{ char type;
int charge;
cout<<"Input Outpatient type ('N' = Normal | 'M' Mild | 'S' = Serious) : ";
cin>>type;
cout<<"\n";
if(type=='n')
{ charge=70;

8

cout<<"Your Charges is : RM "<<charge<<"\n\n";}

else
if(type=='M' || type=='m')
{ charge=100;
cout<<"Your Charges is : RM "<<charge<<"\n\n";}

else
if(type=='S' || type=='s')
{ charge=200;
cout<<"Your Charges is : RM "<<charge<<"\n\n";}

else
{ cout<<"Invalid type !"<<endl<<endl; }
return charge;
}
float WardedPatientCharge(char patient,char wardtype,int days)
{ int charge;
if(wardtype=='N'|| wardtype=='n')
{ charge=150*days;
cout<<"Your Charges is : RM "<<charge<<"\n"; }

else
if(wardtype=='M' || wardtype=='m')
{ charge=200*days;
cout<<"Your Charges is : RM "<<charge<<"\n"; }

else
if(wardtype=='S' || wardtype=='s')
{ charge=300*days;
cout<<"Your Charges is : RM "<<charge<<"\n"; }

else
{ cout<<"Invalid type !"<<endl<<endl; }
return charge;
}

9

TASK 4

10

You might also like