top of page

HW1  due on 217/17

1. Write  a program that prompts the user to enter two integers. Then calculate and output to the screen:

    a.  the sum of the 2 integers

    b.  the product of the 2 integers

    c.  the difference between the two integers

    d.  the modulus between the 2 integers

2. Write  a program that prompts the user to enter three integers. Then compare the  3 integers  and output to the screen :

    a. the smallest integer

    b. the biggest integer

    c. their sum

    d. their average  

 

HW2 due on 3/10/17

Ex1) : If grade has the value of 60, what will the following code display?

                 if ( grade >= 60 )

                                  cout << "Passed";

 

  1.  nothing.

  2.  60

  3.  Passed

  4.  cout << "Passed";

Ex2) How many times will the following loop print hello? 

                i = 1;

                while ( i <= 10 )

                                cout << "hello"; 

  

  1.  0.

  2.  9.

  3.  10.

  4.  An infinite number of times.

Ex3) What is the final value of x after performing the following operations?

                 int x = 21;

                double y = 6;

                double z = 14;

                y = x / z;

                x = 5.5 * y;

 

  1.  8.25

  2.  5.5

  3.  5

  4.  8

Ex4.) Write a c++ program that outputs all the values that are divisible by 5 for the range 1 to 100.

Homework 3 due on 4/21/2017

Q1:) Given the following function template  

 

 template < class T >

T maximum( T value1, T value2 )

{

   if ( value1 > value2 )

         return value1;

   else

         return value2;

}

 

 What would be returned by the following two function calls?

maximum( 2, 5 );

maximum( 2.3, 5.2 );

  •  a)   5 and a type-mismatch error.

  •  b)  5 and 5.2.

  • c)   2 and 2.3.

  • d)  Two error messages.

 

Q2:)  What does the function mystery1()  do ? Explain

 

#include <iostream>
using namespace std;

void mystery1( char *, const char * ); // prototype

int main()
{
   char string1[ 80 ];
   char string2[ 80 ];

   cout << "Enter two strings: ";
   cin >> string1 >> string2;
   mystery1( string1, string2 );
   cout << string1 << endl;
} // end main


void mystery1( char *s1, const char *s2 )
{
   while ( *s1 != '\0' )
      s1++;

   for ( ; *s1 = *s2; s1++, s2++ )
      ; // empty statement
} // end function mystery1

 

Q3:)   cin.getline( superstring, 30 );   is equivalent to which of the following?

  • a)   cin.getline( superstring, 30, '\0' );

  • b)   cin.getline( superstring, 30, '\n' );

  • c)   cin.getline( superstring, 30, '\s' );

  • d)  cin.getline( superstring, 30, '\t' );

 

Q4:) Which file open mode would be used to write data only to the end of an existing file?

  • a)  ios::app

  • b)  ios::in

  • c)  ios::out

  • d)  ios::trunc

 

Q5:) Given the class definition:  

 class CreateDestroy

{

public: 

   CreateDestroy() { cout << "constructor called, "; }

   ~CreateDestroy() { cout << "destructor called, "; }

};

 What will the following program output?

 

int main()

{

   CreateDestroy c1;

   CreateDestroy c2;

   return 0;

}

 

  •  a)  constructor called, destructor called, constructor called, destructor called,

  •  b)  constructor called, destructor called,

  •  c)   constructor called, constructor called,

  •  d)  constructor called, constructor called, destructor called, destructor called,

bottom of page