void FormLetter(string first,string last, string address, int age) { cout << "Dear " << first << "," << endl << endl; cout << "Now that you're " << age << " years old you "; cout << "need to provide " << endl; cout << "for the " << last << " family. Invest for the future, " << first << ","<< endl; cout << "Make life at " << address << " happy: give us money today!" << endl << endl << endl; } bool IsAbundant(double a, double b, double c) // precondition: a, b, c are lengths of sides of a triangle // postcondition: returns true if triangle is abundant, otherwise // returns false { double perim = a+b+c; double semi = 0.5*perim; double area = sqrt(semi * (semi - a) * (semi - b) * (semi - c)); return perim > area; } int TotalMoves() // postcondition: returns sum of rolling two six-sided dice // where dice are rolled until doubles are NOT thrown { Dice d(6); int first = d.Roll(); int second = d.Roll(); int total = first + second; // sum of first two to start while (first == second) { first = d.Roll(); second = d.Roll(); total += first + second; } return total; } int Reverse(int val) //precondition: 0 < val //postcondition: returns number whose digits are reverse of val's digits { int rev = 0; int digit; while (val > 0) { digit = val % 10; // get ones digit rev = rev * 10 + digit; // build number up val /= 10; // chop off last digit } return rev; } #include #include // for class ifstream #include "dukestudent.h" // for class DukeStudent main() { DukeStudent student; ifstream flexfile; string filename; string ssn; double expense; cout << "enter name of file: "; cin >> filename; flexfile.open(filename); flexfile >> ssn; // first line is soc-sec. number student.Init(ssn); cout << "name is " << student.Name() << endl; cout << "initial Flex balance = $" << student.Flex() << endl; while (flexfile >> expense) { student.AddToFlex(-1 * expense); // deduct expenses } cout << "after expenses balance = $" << student.Flex() << endl; } main() { int maxRun = 0; // longest run length int maxValue = 0; // longest run value int run = 0; // current run length int roll; // current roll int lastRoll = 0; // last value rolled int k; Dice d(12); for(k=0; k < 1000000; k += 1) { roll = d.Roll(); if (roll == lastRoll) { run += 1; // current run is longer } else { run = 1; // start a new run, length is 1 } if (run > maxRun) // current run larger than max so far? { maxRun = run; maxValue = roll; } lastRoll = roll; } cout << "longest run = " << maxRun << " value rolled = "; cout << maxValue << endl; }