In: Computer Science
Fill-In-The-Blanks 13. Complete the code by filling in the blanks for each question below. (Length of blank doesn’t matter.)
a) Print out the contents of the array airlines. #include #include ________________ using namespace std; int main () { string airlines[] = {"american","pan-am","southwest"}; for (int i = 0;_______________;i++) cout << ____________ << endl; return 0; }
b) Read in 5 integers from the user and write them back out in reverse order int numbers[5]; for(int i = 0; ___________; _________) cin >> numbers[i]; for(int i = 4; ___________; _________) cout << numbers[i] << endl;
c) Sets a pointer and outputs the dereferenced value. int x = 5; int *xPtr; // xPtr "points to" x xPtr = _____________; cout << ___________ << endl;
Please read comments for your understaning ...
==============================================
/*
* Print out the contents of the array airlines. #include
* #include ________________ using namespace std; int main ()
* { string airlines[] = {"american","pan-am","southwest"};
* for (int i = 0;_______________;i++) cout << ____________
<< endl; return 0;
* }
b) Read in 5 integers from the user and
write them back out in reverse order int numbers[5];
for(int i = 0; ___________; _________) cin >>
numbers[i];
for(int i = 4; ___________; _________) cout << numbers[i]
<< endl;
c) Sets a pointer and outputs the dereferenced value.
int x = 5; int *xPtr; // xPtr "points to" x xPtr = _____________;
cout << ___________ << endl;
*/
#include <iostream> //Header that defines the standard
input/output stream objects
using namespace std;
int main() {
//===========================================================//
//Q1.
//===========================================================//
string airlines[] = { "american", "pan-am",
"southwest" };
for (int i = 0; i<sizeof(airlines)/sizeof(string);
i++) //sizeof(airlines)/sizeof(string) gets the size of
airlines
cout << airlines[i] <<
endl; //accessing the elements of array one by one
//===========================================================//
//===========================================================//
//Q2.
//===========================================================//
int numbers[5];
//Here loop will repeat i=0,1,2,3,4 and fails at
i<5 when i = 5 so finally we will get five elements in out
integer array
for(int i = 0; i<5; i++) cin >>
numbers[i];
//Here loop will repeat i=4 ,3,2,1,0 and fails in
condition check i>=0 here you keep your eye on = symbol at
condition check[i<=4]
//if = not there it will take only 4 elemets not 5 as
we required
for(int i = 4; i>=0; i--) cout << numbers[i]
<< endl;
//===========================================================//
//===========================================================//
//Q3.
//===========================================================//
int x = 5; int *xPtr; // xPtr "points to" x
xPtr = &x;
cout <<"Dereferenced value :"<< *xPtr
<< endl;
//===========================================================//
return 0;
}
==================================