Page 259 - Computer_Science_F5
P. 259

Computer Science  Demonstration of Modulo division
                 Program Example 4.14:




                  #include<iostream>
          FOR ONLINE READING ONLY
                  using namespace std;

                  int main()
                  {
                         int sec, min, hrs;
                         cout<<”Enter seconds: “;
                         cin>>sec;

                         min = sec/60;
                         hrs = min/60;
                         int remainSeconds = sec%60;
                         cout<<sec<<” seconds is “<<hrs<<” hours, “<<min<<” minutes

                         and  “<<remainSeconds<<” seconds”<<endl;
                         return 0;
                  }


              Output:













                                     Figure 4.30: Output of the program


           (b) Assignment operators
           Assignment operators  are  responsible  for assigning value  to  the  variable.  The
           value assigned can either be constant, variable or expressions. The syntax used to
           assign value to the variable is variable = value; for example x=10; or y=a+1. The
           assignment operations always take the value from right to left. This means that, if
           two variables a and b are assigned as a = b, then, the value of a will be replaced by
           the value of b and not otherwise. The following Program Example 4.15 demonstrates
           the assignment operations in C++ programming. The output is shown in Figure 4.31.


                                                 250
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   250                                                     23/07/2024   12:33
   254   255   256   257   258   259   260   261   262   263   264