Page 103 - Modular_V2.0_C++_Flikpbook
P. 103

MORE SOLVED PROGRAMS

                                                                2
                 Program 4: To calculate the value of E = mc  using functions, if m = 100 kg and c = 2 m/s.
                 #include<iostream.h>
                                                                     DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program:
                 #include<math.h>
                                                                 Mass (m) = 100 kg
                 #include<conio.h>
                                                                 Speed of Light (c) = 2 m/s
                 void main()                                     Energy (E = mc^2) = 400 Joules
                 {

                     double energy, mass = 100, lightspeed = 2;
                     clrscr();
                     cout<< "Mass (m) = " << mass << " kg";
                     cout<< "\nSpeed of Light (c) = " << lightspeed << " m/s";
                     energy = mass * pow(lightspeed, 2);

                     cout<< "\nEnergy (E = mc^2) = " << energy << " Joules";
                     getch();
                 }
                 Program 5: To take a character as input and check whether it is an uppercase letter. If it is an

                 uppercase letter, then change it into lowercase.
                 #include<iostream.h>
                 #include<ctype.h>
                 #include<conio.h>

                 void main()                                         DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program:
                 {                                               Enter a character: R
                     char ch;                                    Character in lowercase: r
                                                                 _
                     clrscr();
                     cout<< "Enter a character: ";
                     cin>> ch;
                     if(isupper(ch))
                     {
                          cout<< "Character in lowercase: " << (char)tolower(ch) << endl;
                     }

                     else
                     {
                         cout<< "Character is not an uppercase letter." << endl;
                     }                                               DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program:

                     getch();                                    Enter a character: t
                                                                 Character is not an uppercase letter.
                 }
                                                                 _





                                                                                                                 101
                                                                                 Header Files and Library Functions
   98   99   100   101   102   103   104   105   106   107   108