Winter 2020

PIC 10A: Introduction to Programming

Discussion Section 3A

Wonjun Lee



Week6

Tuesday

Will be uploaded ...

Thursday

Exercise P4.1.

Compute bank balances by prompting for the initial balance and the interest rate. Then print the balance after 10, 20, and 30 years.

Solution
#include < iostream >

using namespace std;

int main()
{
  // TODO
}
Exercise P4.7.

Write functions

double sphere_volume(double r);

double sphere_surface(double r);

double cylinder_volume(double r, double h);

double cylinder_surface(double r, double h);

double cone_volume(double r, double h);

double cone_surface(double r, double h);


that compute the volume and surface area of a sphere with radius r, a cylinder with a circular base with radius r and height h, and a cone with a circular base with radius r and height h. Then write a program that prompts the user for the values of r and h, calls the six functions, and prints the results.

Solution
#include < iostream >

using namespace std;

int main()
{
  // TODO
}
Exercise P4.9.

Leap years. Write a predicate function


bool leap_year(int year)


that tests whether a year is a leap year: that is, a year with 366 days. Leap years are necessary to keep the calendar synchronized with the sun because the earth revolves around the sun once every 365.25 days. Actually, that figure is not entirely precise, and for all dates after 1582 the Gregorian correction applies. Usually years that are divisible by 4 are leap years, for example 1996. However, years that are divisible by 100 (for example, 1900) are not leap years, but years that are divisible by 400 are leap years (for example, 2000).

Solution
#include < iostream >

using namespace std;

int main()
{
  // TODO
}