80 likes | 162 Views
Riyadh Philanthropic Society For Science Prince Sultan College For Women Dept. of Computer & Information Sciences CS 101 Computer Programming I Lab 10 -Answer. Draws 2 parallel lines. Draws a horizontal line. Exercise 1. What does the following functions do? void draw_base() {
E N D
Riyadh Philanthropic Society For Science Prince Sultan College For Women Dept. of Computer & Information Sciences CS 101 Computer Programming I Lab 10 -Answer
Draws 2 parallel lines Draws a horizontal line Exercise 1 What does the following functions do? void draw_base() { cout << " ----------\n"; } void draw_parallel() { cout << "| |\n"; cout << "| |\n"; cout << "| |\n"; }
Exercise 2 Given the previous two functions, write the main function of a program that draws a rectangle. int main() { draw_base(); /* calling draw_base function */ draw_parallel(); /* calling draw_parallel function */ draw_base(); /* calling draw_base function */ return 0; }
Exercise 3 Trace the following program - in what order will it execute? /* draws a rectangle */ #include <iostream> using namespace std; void draw_base(); /* declaration of draw_base function */ void draw_parallel(); /* declaration of draw_parallel function */ int main() { draw_base(); /* calling draw_base function */ draw_parallel(); /* calling draw_parallel function */ draw_base(); /* calling draw_base function */ return 0; } void draw_base() /* definition of draw_base function */ {cout <<(" ----------\n");} void draw_parallel() /* definition of draw_parallel function */ {cout << "| |\n"; cout << "| |\n"; cout << "| |\n";}
Exercise 4 Draw a structure chart for a program with (some) function subprograms that displays HIHO in a vertical column on block letters.
Exercise 5 Write a program that displays HIHO in a vertical column on block letters (using three functions).
continue Exercise 5 - Solution /* displaying HIHO in a vertical column on block letters */ #include <iostream> using namespace std; void draw_H(); /* declaration of draw_H function */ void draw_I(); /* declaration of draw_I function */ void draw_O(); /* declaration of draw_O function */ int main() { draw_H(); /* calling draw_H function */ draw_I(); /* calling draw_I function */ draw_H(); /* calling draw_H function */ draw_O(); /* calling draw_O function */ return 0; } void draw_H() /* definition of draw_H function */ { cout <<"* *\n"; cout <<"* * *\n"; cout <<"* *\n\n"; }
Exercise 5 - Solution void draw_I() /* definition of draw_I function */ { cout << " *\n"; cout << " *\n"; cout << " *\n\n"; } void draw_O() /* definition of draw_O function*/ { cout << "* * *\n"; cout << "* *\n"; cout << "* * *\n\n"; }