In Class Lab 1(short lab) (Taken from Prof Tausner)

 - a short programming project to be done in one lab session

 

This lab has three parts:


// Programmer: type your name here
// Date completed: type today's date
// Program to obtain a decimal number from the user and
// and display the number squared and to the 3rd power.
 
#include <iostream>
#include <iomanip>
using namespace std;
 
int main ( )
{

     double  num;          // decimal number variable
     double numsq;        // will hold number squared
     double num_3rd;      // will hold number cubed
 
    
     // Obtain a decimal number
     cout << "Please type a decimal number: " ;
     cin >> num;
        
     numsq = num * num;        // compute num squared
     num_3rd = numsq * num;    // compute num to the 3rd power
 
     // Display the results
     cout << fixed << setprecision(2);
     cout << setw(40) << left << "The number = " << num << endl;
     cout << setw(40) << left << " The number squared = " <<  numsq << endl;
     cout << setw(40) << left << " The number cubed = " << num_3rd << endl;
     cout << endl;
 
     return 0;
}


After the program successfully runs, experiment with it as described here:

Add the following to the program

Give these new variables meaningful names.


Here is an example of the results you will get:
Assume the number input is 5
then      number squared will equal 25.00
             number cubed will equal 125.00
             number4 will equal 625.00
             number5 will equal 3125.00
             number6 will equal 15625.00