Computer Programming, Exercises of Computer Science

This is the Exercise of different Programming questions. included Loops & Funtions

Typology: Exercises

2017/2018

Uploaded on 11/13/2018

mfaizshahid
mfaizshahid 🇵🇰

1 document

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Enrollment: 03-134181-017
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Computer Programming and more Exercises Computer Science in PDF only on Docsity!

Contents

  • Question No:01:............................................................................................................................................
    • Question No: 01 Algorithm:
  • Question No:02:............................................................................................................................................
    • Question No: 02 Algorithm:
    • Question No:02 Flow Chart:
  • Question No:03:............................................................................................................................................
    • Question No:03 Algorithm:
    • Question No 03 Flow Chart:
  • Question No:04:............................................................................................................................................
    • Question No: 04 Program code:
    • Question No 04 OUTPUT:
  • Question No:05:..........................................................................................................................................
    • Question No:05 Program code:
    • Question No: 05 Output:
  • Question No :
    • Question No : 06 Program code:
    • Question No: 06 Output:
  • Question No:
    • Question No 07 Program code:
    • Question No: 07 Output:
  • Question No:
    • Question No: 08 Program code:
    • Question No: 08 Output:
  • Question No:
    • Question No: 09 Program code:
    • Question No: 09 Output:

Question No:02:

Question No: 02 Algorithm:

→Start →Read x

→Read y

→Read r

→r=x/y

→If (y==0)

→Not possible

→else

→Display quotient

→End

Question No:02 Flow Chart:

→Average= (obtained marks/total marks)*

→Final marks of class = final marks of class + obtained marks of class

→Overall average of whole class = (final marks of class / total marks of class)*

→Display Overall Average of class

→End

Question No 03 Flow Chart:

Question No 04 OUTPUT:

Question No:05:

Question No:05 Program code:

#include using namespace std; int main() { int y; /me assume 'y' as number of years/ float ia, r, f = 0; /me assume 'ia' as initial amount, 'r' as Rate of Interest, 'f' as balance at the end of years/

cout << "\n Enter the Initial Amount:"; cin >> ia; cout << "\nEnter the number of years:"; cin >> y; cout << "\nEnter the rate of interest (percent per year):"; cin >> r; r = r / 100; /* use this formula to convert rate of interest form point(.) into number*/ f = ia;

for (int i = 1; i <= y; i = i + 1) /using for loop/ { f = f + (f*r); } cout << "\nAt the end of the year the balace will be:" << f; system("pause"); return 0; }

Question No: 05 Output:

Question No: 06 Output:

Question No: 07

Question No 07 Program code:

#include using namespace std; int main() { //s=sales, sc=off stock cost, ta=text amount , p=profit double s, ta, sc, p = 0; { cout << "\nEnter sales:"; cin >> s; ta = s * 0.3;/convert 30%(according to situation in Question) into 0.3 by 30/100=0.3/ cout << "\n Text amount is:" << ta; sc = s * 0.3;/convert 30%(according to situation in Question) into 0.3 by 30/100=0.3/ cout << "\n Stock Cost is:" << sc; p = s - (ta + sc); cout << "\n Profit is:" << p; } system("pause"); return 0;

}

Question No: 07 Output:

Question No: 08 Output:

Question No: 09

Question No: 09 Program code:

#include using namespace std; int main() { int h = 0, e = 0; /assume 'h' as hours worked 'e' as over time pay / float r, s = 0; /assume 'r' as hourly rate and 's' as salary/

while (h != -1) /using while loop and if condition/ { cout << "\nEnter number of hours worked(-1 to End):"; cin >> h;

if (h == -1) { cout << "\n bye bye:"; system("pause"); exit(0); } else { cout << "\nEnter hourly rate of the worker($00.00):"; cin >> r; } { if (h <= 40) /according to Question if hours aren't greater then 40 then no overtime pay/ { s = rh; cout << "\n Salary is:" << s; } else { /if hours are greater then 40 then overtime pay starts/ int e = h - 40; h = h - e; s = rh + (r1.5)e; cout << "\nSalary is:" << s; } } }

return 0; system("pause");

}