1 / 8

Riyadh Philanthropic Society For Science Prince Sultan College For Women

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() {

teige
Download Presentation

Riyadh Philanthropic Society For Science Prince Sultan College For Women

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Riyadh Philanthropic Society For Science Prince Sultan College For Women Dept. of Computer & Information Sciences CS 101 Computer Programming I Lab 10 -Answer

  2. 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"; }

  3. 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; }

  4. 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";}

  5. Exercise 4 Draw a structure chart for a program with (some) function subprograms that displays HIHO in a vertical column on block letters.

  6. Exercise 5 Write a program that displays HIHO in a vertical column on block letters (using three functions).

  7. 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"; }

  8. 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"; }

More Related