}
}
+void ch4pe5(void){
+ for(int i=1; i < 10; i++){
+ for(int j=0; j < i; j++){
+ cout << i << " ";
+ }
+ cout << endl;
+ }
+}
void ch4pe6(void)
{
}
}
+void ch4pe7(void){
+ int lines = 10;
+ for(int i=1; i <= lines; i++){
+ for(int j=0; j < (lines-i); j++) cout << " ";
+ for(int j=1; j < i; j++) cout << "0";
+ cout << "0";
+ for(int j=1; j < i; j++) cout << "0";
+ cout << endl;
+ }
+}
+
void ch4pe8(void)
{
for (int X=0;X<10;X++)
}
}
+void ch5pe3(){
+ vector<int> input (10);
+ int target = 0;
+ int count = 0;
+
+ for(int i=0;i<10;i++){
+ cout << "Please input a number: ";
+ cin >> input[i];
+ }
+ cout << "Please input target value: ";
+ cin >> target;
+
+ for(int i=0;i<10;i++){
+ if(input[i] = target) count++;
+ }
+
+ cout << "The target value appears " << count << " times in the array";
+}
+
void ch5pe4()
{
int arrayPosi[9]={0}, Position, HitorMiss, Bat, n, Leave;
}
}
+void ch5pe5(){
+ vector<int> atBats(9);
+ vector<int> hits(9);
+ vector<int> bases(9);
+ int pos, rec;
+
+ bool over = false;
+
+ while(!over){
+ cout << "Position: ";
+ cin >> pos;
+ if(pos != -1){
+ cout << "Record: ";
+ cin >> rec;
+ if(rec > 0){
+ hits[pos-1]++;
+ bases[pos-1] += rec;
+ }
+ atBats[pos-1]++;
+ }
+ else{
+ over = true;
+ }
+ }
+
+ cout << "The batting average for each position was: " << endl;
+ for(int i = 0; i < 9; i++){
+ cout << "Position " << i+1 << " batting average is " << float(hits[i])/float(atBats[i]) << endl;
+ }
+ cout << endl << "The slugging percentage for each position was: " << endl;
+ for(int i = 0; i < 9; i++){
+ cout << "Position " << i+1 << " slugging percentage is " << float(bases[i])/float(atBats[i]) << endl;
+ }
+}
+
void ch5pe6()
{
int T=0;
}
}
+void ch5pe7(){
+ vector<string> usr(10);
+ vector<string> pass(10);
+ string inputuser, inputpass;
+ bool complete = false;
+ bool usrfnd = false;
+
+ for(int i=0;i<10;i++){
+ cout << "Please enter a username: ";
+ cin >> usr[i];
+ cout << "Please enter a password for " << usr[i] << ": ";
+ cin >> pass[i];
+ }
+
+ while(!complete){
+ int pos = 0;
+
+ cout << "Please enter your username: ";
+ cin >> inputuser;
+ for(int i=0;i<10;i++){
+ if(usr[i] == inputuser){
+ pos = i;
+ usrfnd = true;
+ }
+ }
+ if(usrfnd){
+ cout << "Please enter your password: ";
+ cin >> inputpass;
+
+ if(pass[pos] == inputpass){
+ cout << "Access Granted" << endl;
+ complete = true;
+ }
+ else{
+ cout << "Username and password do not match" << endl << endl;
+ }
+ }
+ else{
+ cout << "Username not found" << endl << endl;
+ }
+ }
+}
+
+void ch5pe8(){
+ vector<int> scores(6);
+ int swaps = 1;
+ int tot = 0;
+
+ for(int i = 0; i < 6; i++){
+ cout << "Input score: ";
+ cin >> scores[i];
+ }
+
+ while(swaps != 0){
+ swaps = 0;
+ for(int i=0; i < 5; i++){
+ if(scores[i] > scores[i+1]){
+ int a = scores[i];
+ scores[i] = scores[i+1];
+ scores[i+1] = a;
+ swaps++;
+ }
+ }
+ }
+ for(int i=1; i < 5; i++) tot+=scores[i];
+
+ cout << "Highest score : " << scores[5] << endl;
+ cout << "Lowest score : " << scores[0] << endl;
+ cout << "Olympic Average : " << float(tot)/4.0 << endl;
+
+
+}//TODO
+
int main(void){
cout << "Please select the program you would like to run:" << endl;
cout << "\t" << "1. Ch.4 PE 2" << endl;
case 2:
ch4pe4();
break;
+ case 3:
+ ch4pe5();
+ break;
case 4:
ch4pe6();
break;
+ case 5:
+ ch4pe7();
+ break;
case 6:
ch4pe8();
break;
case 8:
ch5pe4();
break;
+ case 9:
+ ch5pe5();
+ break;
case 10:
ch5pe6();
break;
+ case 11:
+ ch5pe7();
+ break;
+ case 12:
+ ch5pe8();
+ break;
default:
cout << "Sorry, option unimplemented!";
break;