CS 630 - Computing Fundamentals I - Spring 2004
Homework 2


Loyola College > Department of Computer Science > CS 630 > Homework > Homework 2

Due

Wednesday, June 16th at the beginning of class
Email programs (.cpp files) to lawrie@cs.loyola.edu

Problems

Problem 1: Complete Card Exercise (Download file: ex1.cpp)

Problem 2: What does the following program print? (This exercise asks you to read the code. If you want to execute the code, please use it to verify your answer.)

#include <iostream>
using std::cout;
using std::endl;

// function main begins program execution
int main()
{
   int y;               // declare y
   int total = 0;       // intialize total

   for (int x = 1; x <= 10; x++)  // loop 10 times
   {
      y = x * x;           // perform calculation
      cout << y << endl;   // output result 
      total += y;          // add y to total
   }  // end for 

   cout << "Total is " << total << endl;   // display results

   return 0;   // indicate successful termination
}  // end function main

Problem 3: 2.27

Problem 4: 2.35 (Programming - recall a valid triangle's longest side is less than the sum of the other two sides.)

Problem 5: 2.39

Problem 6: 2.49 (Programming - the user will enter a product number of -1 when she has entered all the data. Use constants where appropriate.)

Problem 7: 2.52