Prog Chapter 8 Answers Part 1
Prog Chapter 8 Answers Part 1
Prog Chapter 8 Answers Part 1
#include <iostream>
#include <conio> error/s: 1. #include <conio> : must be
#include <conio.h>
2. using namespace std;
int main () 3. "size" is not declared: must
be int size = 5;
{
int num[5] = {1,2,3,4,5}; Output: kapag na correct na yung
mga mali
double grade[] = {78,85,86,82,85}; 1 2 3 4 5
float ave[5] = {82.4,85.5}; 78 85 86 82 85
int age[5]; 82.4 85.5 0 0 0
age [0] = 16; 16 19 20 18 13
age [1] = 19;
age [2] = 20;
age [3] = 18;
age [4] = 13;
age [5] = 17;
int i;
getch();
return 0;
}
Program Activity 2:
#include <iostream>
#include <stdlib> error/s: 1. #include <stdlib> :
must be #include <stdlib.h>
2. using namespace std;
const int size = 10; 3. on line 10:
cout<<"Enter " <<size"<< numbers: "<<endl; : must be cout<<"Enter numbers: "<< size
<<endl;
4. (optional) on line 22:
cout<<"largest number: "<<max; : must be cout<<"largest number: "<<max << endl;
int main ()
{
int num[size]; Output: kapag na correct na
(input ko ay 9 to 1)
cout<<"Enter " <<size"<< numbers: "<<endl; Enter numbers: 10
for(int i=0;i<size;i++) enter a number: 9
{ enter a number: 8
cout<<"enter a number: "; enter a number: 7
cin>>num[i]; enter a number: 6
} enter a number: 5
int max=num[0]; enter a number: 4
enter a number: 3
for (int j =0;j<size;j++) enter a number: 2
if(max<num[j]) enter a number: 1
max=num[j]; enter a number: 0
largest number: 9
cout<<"largest number: "<<max; press any key to
continue.... (dahil sa system ("pause"))
system("pause");
return 0;
}
Program Activity 3:
#include <iostream>
void ballon(int[]); error/s: 1. using namespace
std;
const int size = 5;
Program Activity 6:
#include <cstring>
#include <iostream>
Error/s: 1. #include <conio> : must be #include <conio.h>
#include <conio>
2. using namespace std;
int main()
{
string str1 = "Hello";
Output:
string str2 = "World";
str1 and str2: HelloWorld
string str3;
str3: Welcome
int len;
str3 and "Philippines": Welcome Philippines
str3.length(): 19
cout<<"str1 and str2: " << str1 << str2<< endl;
Calling to find ("Phil"): 8
// copy str1 to str3
Calling substr(0,2): We
str3 = "Welcome ";
Calling substr(4): ome Philippines
cout << "str3: " << str3 << endl;
Welcome to Philippines
//will look at a designated index and insert the string, as the second
parameter. In that place
cout << str3.insert(8,"to ") << endl;
getch;
return 0;
}