Page 255 - Computer_Science_F5
P. 255

Computer Science       Exercise 4.9                                      18  2 .  % 


             1.  Write a C++ program that will enable customers to know the Value-Added Tax
                to be paid for any purchase price of the commodity. The VAT rate of 18.2%
                should be declared as a constant, and the formula should be (VAT
          FOR ONLINE READING ONLY
                Purchase prices).
             2.  Differentiate the terms variable and constant as applied in C++ programming
             3.  Create a C++ program that prompts a user to enter a radius of the sphere. The
                program should calculate and display the volume of the sphere as output. (Hint:

                The formula for calculating the volume of the sphere is   4  r   3 , r represents the
                radius of the sphere). Use Table 4.6 in your declaration. 3

                 Table 4.6: Declaration

                Data name                    Data type             Declaration type
                Pie ( ) =3.1415926          Double                Constant
                Radius                       Float                 Variable
                Volume                       Double                Variable

            4. (a)   What are the benefits of using   5.   Consider the following program:
                    constants in a C++ program?           #include <iostream.h>
                                                          using namespace std;
                (b)   What  is  wrong  with  the
                    following C++ program?                int main()
                                                          {
                    Explain.
                                                          int a;
                                                          int b;

                #include<iostream>                        a=2;
                                                          b=5;
                #define PI = 3.142;                       a=b;
                using namespace std;                      b=4;
                int main()                                cout << “a= “ << a << endl;
                {                                         cout << “b= “ << b<< endl;
                        double temp = PI*5;               return 0;
                        cout<<temp<<endl;                 }
                        return 0;                         (a)  What is the output of this
                }                                             program?
                                                          (b)  Using  a  diagram,  illustrate
                                                              how memory changes during
                                                              variable assignment.


                                                 246
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   246                                                     23/07/2024   12:33
   250   251   252   253   254   255   256   257   258   259   260