Sie sind auf Seite 1von 5

ANSWER 2 : /* This program written to print appropriate message with the obtained grades*/ # include <iostream.

h> void main ( ) { char cGrades; // declaration of variable cout<<"Please enter your grades : "; cin>> cGrades; // take input if (cGrades == 'A' || cGrades == 'a'){ // if people obtained gred A cout<<"you've got A" ; // print output } else if (cGrades == 'B' || cGrades == 'b'){ cout<<"you've got B"; } else if (cGrades == 'C' || cGrades == 'c'){ cout<<"you've got C"; } else if (cGrades == 'D' || cGrades == 'd'){ cout<<"you've got D"; } else { cout<<"you've got F"; } }

ANSWER 3

/* This program written to print appropriate message with the obtained grades by using switch case */ # include <iostream.h>

void main ( ) { char cGrades; // declaration of variable cout<<"Please enter your grades : "; cin>>cGrades; // take input switch (cGrades){ case 'A': cout<<"you've got A"; break; case 'B': cout<<"you've got B"; break; case 'C': cout<<"you've got C"; break; case 'D': cout<<"you've got D"; break; default : cout<<"you've got F";} } ANSWER 4 : // This program written to calculate the sum of number.

# include <iostream.h>

void main ( ) { int iX, iNom , iSum = 0; // declaration of variable

for (iX=0; iX<5; iX++){

cout<<"Please enter your number : "; cin>>iNom; // take input

iSum = iSum + iNom; // process to calculate the sum of numbers } cout<<"the sumation is : "<<iSum ; //print the result } ANSWER 5 : # include <iostream.h> void main ( ) { int iX = 0, iNom , iSum = 0; while (iX<5){ cout<<"Please enter your number : "; cin>>iNom; iX++; iSum = iSum + iNom; } cout<<"the sumation is : "<<iSum ; }

ANSWER 6 : # include <iostream.h>

void main ( ) { int iX = 0, iNom , iSum = 0; // declaration of variables

do {

cout<<"Please enter your number : "; cin>>iNom;

iX++;

iSum = iSum + iNom; // process to calculate numbers } while (iX<5); cout<<"the sumation is : "<<iSum ; // print result }

ANSWER 7 : #include <iostream.h> int iGetMultiplication(int iNumber1,int iNumber2); int main(){ int iDarab,iNumber1,iNumber2; iDarab= iGetMultiplication(iNumber1 ,iNumber2); cout<<iDarab; return 0; } /************************************************************* *********************************** *Function : iGetMultiplication() *Description: THIS function will do multiplication of two numbers * *Input parameter:iNumber1,iNumber2 *returns:0,iHasildarab ************************************************************** **********************************/ int iGetMultiplication(int iNumber1,int iNumber2){ int iHasilDarab;

cout<< "sila masukkan nombor pertama "; cin>>iNumber1; cout<< "sila masukkan nombor kedua "; cin>>iNumber2; iHasilDarab=iNumber1*iNumber2; return iHasilDarab; } Terima kasih atas perhatian puan. Yang Benar (NUR IZU SALIHAH BT AB RAHIM) D201258519-Group A 013-5310069