12

REVISION.pptx

Embed Size (px)

Citation preview

Page 1: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 1/12

Page 2: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 2/12

FINAL EXAM STRUCTURE

Output (15%)

Debugging (15%)

Writing Simple Statements (20%)

Writing Simple Program x 2 (20%)

Writing Program with Functions x 2 (30%)

Page 3: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 3/12

Page 4: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 4/12

Looking For Output…. int beta =6;

switch(beta)

{ case 1:case 3:

beta = beta + 2;

case 4:

beta = 2 * beta;break;

case 6:

beta++;

case 7:

beta = 2*beta;

case 8:beta = beta +5;

break;

default:

beta--;}

cout<<beta;

19

Page 5: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 5/12

Function (2 Types)

return type

string getName(string N, string lN){ return fN + “ “ + lN; }

void type

void printName(string fN, string lN){ cout<< fN << “ “ << lN; }

Page 6: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 6/12

Writing Simple StatementsAssume that all variables are declared. Write C++statements to accomplish each of the following:

Assign the sum of the pre-decremented value of aand b to c.

c = --a + b;

Print out a message “You are clever” if mark isbetween 80 and 100 and mark is not 0

 if( (mark>=80 && mark<=100) && mark!=0)

  { cout<<“You are clever”;  }

Page 7: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 7/12

Writing Simple Statements Sum the even integers between 1 and 99 using a for

statement and assign the result to sum.

int sum=0;

for(int i=1;i<=99;i++)

{ if (i%2==0)

sum+=i; // sum=sum+i

}

Set the value of the fifth element of the array alpha to themultiplication result of the first and third elements.

alpha[4] = alpha[0] * alpha[2]; 

Page 8: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 8/12

Writing Simple Statements Compute the sum and average of all the five elements in the array alpha

and output the sum, average and value of each element.

double average=0.0;

int sum = 0;for (int i = 0; i<5;i++)

{

 sum=sum+ alpha[i];

 }

average = sum/5;

cout<<“Sum is”<<sum<<endl;

cout<<“Average is”<<average<<endl;

for (int i=0; i<5; i++)

cout<<alpha[i ];

Page 9: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 9/12

Writing simple programWrite a C++ program that display table of conversion

between feets and meters begins from 0 feet to 50

feet with every 5 feet increment using for loop. Theconversion formula is: meter = 0.305 * foot

cout<< setw(10)<<"Feet" << setw(10)<<"Meter"<<endl;

for(int ft=0; ft<=50; ft+=5)cout<<setw(10)<<ft<<setw(10)<<0.305*ft<<endl;

Page 10: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 10/12

Page 11: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 11/12

const int N = 3; 

/* The function for adding two matrices */

void addMatrix(const double a[][N], const double b[][N], doublec[][N]) 

/* The function to print result of addition*/

void printResult(double m1[][N], double m2[][N], double m3[][N],char op) 

Page 12: REVISION.pptx

8/14/2019 REVISION.pptx

http://slidepdf.com/reader/full/revisionpptx 12/12

Each element cij is aij + bij. Hereis the sample run: