c++
CE100 – Home Work #4
Write C++ code (flowchart not needed) to solve the following problems (Q1 & Q2)
Q1. Read a mobile phone number and validate it. If it is valid, simply print the phone
number. Hint: Mobile phone numbers in Kuwait are 8 digits and start with 5, 6 or 9.
Q2. Read a date of birth and validate it as follows: day (1-30), month (1-12) and year (1900- 2019). If the date is valid, print it in this format: day-month-year.
Q3. What is the output of this program? [Write your answer inside this box]
#include <iostream> using namespace std; int main() {
for ( int c = 10; c <= 20; c++ ) { if ( c == 14 ) c += 4;
cout << c << " "; } return 0;
}
[Write your answer inside this box] Q4. What is the output of this program? #include <iostream> using namespace std; int main() {
for ( int c = 10; c <= 20; c+= 2 ) { if ( c == 15 ) break;
cout << c << " "; } return 0;
}
Q5. What is the output of this program? [Write your answer inside this box]
#include <iostream> using namespace std; int main() {
for ( int c = 10; c <= 20; c++ ) { if ( c > 13 && c < 18 ) continue;
cout << c << " "; } return 0;
}
Q6. What should be the missing statement (break or continue?) so that the output of
this program becomes: 10 11 12 13 14
#include <iostream> [Write your answer inside this box] using namespace std; int main() {
for ( int c = 10; c <= 20; c++ ) { if ( c == 15 )
?????????;
cout << c << " ";
} return 0;
}
Q7. What should be the missing condition so that the output of the following program
becomes: 10 11 12 13 14
#include <iostream> [Write your answer inside this box] using namespace std; int main() {
for ( int c = 10; c <= 20; c++ ) {
if ( ?????????? )
continue; cout << c << " ";
} return 0;
}