/* problem 6 */ int num; int negSum = 0; cout << "enter a number> "; cin >> num; while (num != 0){ if (num < 0){ negSum += num; } cout << "enter a number> "; cin >> num; } cout << "sum of negative numbers = " << negSum << endl; /* problem 7 */ void ChangeChar(String & s, char oldChar, char newChar) { int k; int len = s.Length(); for(k = 0; k < len; k++){ if (s[k] == oldChar){ s[k] = newChar; } } } /* problem 8 */ double DiveScore(double scores[], int numScores, int diffFactor) { double low = scores[0]; double high = scores[0]; double sum = 0; int k; for(k = 1; k < numScores; k++){ sum += scores[k]; if (scores[k] > high){ high = scores[k]; } if (scores[k] < low){ low = scores[k]; } } double avg = (sum - low - high)/(numScores - 2); return avg*diffFactor; } /* problem 9 */ StockBroker broker; String name; cout << "enter name of stock "; cin >> name; double openPrice = broker.OpeningPrice(name); double sellPrice = 2*openPrice; double price = broker.CurrentPrice(name); int queries = 1; const int MAX_TRADES = 10000; while (queries < MAX_TRADES && price <= sellPrice){ queries++; price = broker.CurrentPrice(name); } if (price > sellPrice){ cout << ... } else{ cout << ... } /* extra problem */ int longRun = 0; int run = 0; Coin dime; int k; for(k=0; k < numTosses; k++){ if (dime.Flip() == 0){ // tossed a tail? run++; } else{ run = 0; } if (run > longRun){ longRun = run; } } return longRun;