break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
cout << “The month is December” << endl;
break;
default:
cout << “invalid integer input..” << endl;
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
cout << “The day is Saturday” << endl;
break;
return 0;
}
/*Program chapter3_37 */
/* This program prompts the user to enter a date with the format XX/XX, */
/* as in 10/01. The program will input the date and print the season. */
int main()
{
int month(0), day(0);
string theMonth, theSeason;
{
cerr << “Bad input..” << endl;
exit(1);
}
switch(month)
{
case 1:
exit(1);
}
case 2:
exit(1);
}
case 3:
cout << “The month is March” << endl;
exit(1);
}
case 4:
cout << “The month is April” << endl;
}
case 5:
cout << “The month is May” << endl;
exit(1);
}
case 6:
cout << “The month is June” << endl;
exit(1);
}
case 7:
cout << “The month is July” << endl;
exit(1);
}
case 8:
cout << “The month is August” << endl;
exit(1);
}
case 9:
cout << “The month is September” << endl;
exit(1);
}
case 10:
cout << “The month is October” << endl;
exit(1);
}
case 11:
cout << “The month is November” << endl;
exit(1);
}
case 12:
cout << “The month is December” << endl;
exit(1);
}
if(day < 21) theSeason = “Fall”;
else theSeason = “Winter”;
break;
default:
}
Climate Control.
/*Program chapter 3_38 */
/*This program calculates and prints the heat index in degrees given the */
/*relative humidity in percent and the temperature in degrees Fahrenheit */
#include<iostream> //required for cin, cout
using namespace std;
int main()
{
heatIndex = -42.379 + 2.04901523*temp + 10.14333127*relHumidity
cout << “Temperature is ” << temp << endl;
cout << “Relative Humidity is ” << relHumidity << endl;
cout << “Heat Index is ” << heatIndex << endl;
return 0;
}
0.4275*temp*pow(velocity,0.16);
cout << “temp is ” << temp << “, velocity is ” << velocity
<< “, windChillIndex is ” << windChillIndex << endl;
if(windChillIndex < INDEX5)
{
Point Class
/* Program chapter3_41 */
/* This program determines if three line segments can form a triangle */
/* A line segment is defined by two points in a plane, P and Q */
/* The distance formula is used to determine the length of a line seg */
/* Created by Jeanine Ingber on 4/12/16. */
#include <iostream>
#include “Point.h”
#include <cmath>
using namespace std;
int main(int argc, const char * argv[]) {
double x, y, a, b, ls1, ls2,ls3;
bool triangle{false};
b = P.getY() Q.getY();
//Calculate length of line segment defined by P and Q
ls1 = sqrt( pow(a,2) + pow(b,2));
cout << “length of line segment 1 is ” << ls1 << endl;
//Input line segment 2
cout << “enter x and y coordinates of point P for line segment 2” << endl;
cin >> x >> y;
//Input line segment 3
cout << “enter x and y coordinates of point P for line segment 3” << endl;
cin >> x >> y;
//Reset value of point P using mutator methods
P.setX(x);
P.setY(y);
//Determine if these 3 line segments can form a triangle
if( (ls1 + ls2) > ls3 && (ls1 + ls3) > ls2
}
/* Program chapter3_42 This program determines if a */
/* specified point T is inside */
/* a rectangle defined by 4 points in a plane, P,Q,R,S. */
cout << “enter x and y coordinates of point P” << endl;
cin >> x >> y;
//Create point P using parameterized constructor
Point P{x,y};
cout << “enter x and y coordinates of point Q” << endl;
Point S{x,y};
cout << “Rectangle PQRS has been defined.\n”
<< “Enter x and y coordinates of a point, T” << endl;
cin >> x >> y;
Point T{x,y};
}
//Calculate slope of line segment QR
m = (R.getY() Q.getY())/(R.getX() Q.getX());
//A point in the rectangle must lie
//on the same side of QR as S.
//Determine position of S and T, relative to QR
//Determine position of P and T, relative to RS
posP = R.getY() P.getY() + m*(P.getX() R.getX());
posT = R.getY() T.getY() + m*(T.getX() R.getX());
//Determine if P is on the same side as T
if( (posT >= 0 && posP < 0) || (posT < 0 && posP >=0) )
}
cout << “Point T is inside rectangle PQRS.” << endl;
return 0;
}
#include <cmath>
using namespace std;
int main(int argc, const char * argv[]) {
double x, y, m;
double posP, posR, posQ, posT;
//Input 3 points to define a triangle
//Enter points in clockwise order
cin >> x >> y;
//Create point R using parameterized constructor
Point R{x,y};
cout << “Triangle PQR has been defined.\n”
<< “Enter x and y coordinates of a point, T” << endl;
if( (posT >= 0 && posR < 0) || (posT < 0 && posR >=0) )
{
cout << “point T is outside triangle PQR” << endl;
return 0;
}
//Calculate slope of line segment QR
m = (R.getY() Q.getY())/(R.getX() Q.getX());
m = (P.getY() R.getY())/(P.getX() R.getX());
//A point in the triangle must lie
//on the same side of RP as Q
//Determine position of Q and T, relative to RP