Kamis, 27 Maret 2014

Ebook Chapter 5 Problem Solving and Program Design in C

  • 5.11 Figure 5.22 Program to draw a quilt
#include <cstdlib>
#include <iostream>

using namespace std;

int main(void)
{
    int x1,y1,x2,y2,stepX,stepY,foreColor,numBars,width, height;
   
    cout<<"Enter number of bars> ";
    cin>>numBars;
   
    width = getmaxwidth();
    height = getmaxheight();
   
    initwindow(width, height, "Quilt");
   
    x1=0;
    x2=width;
    y1=0;
    y2=height;
   
    stepX = width/(2 * numBars);
    stepX = height/(2 * numBars);
   
    for (int i= 1; i<= numBars; ++i){
        foreColor= i%16;
        setcolor(foreColor);
        setfillstyle(i%12, foreColor);
        bar(x1, y1, x2, y2);
        x1 = x1 + stepX;
        y1 = y1 + stepY;
        x2 = x2 - stepX;
        y2 = y2 - stepY;
        }
       
    closegraph();
    system("PAUSE");
    return EXIT_SUCCESS;

0 komentar:

Posting Komentar

 

Anita © 2010

Blogger Templates by Splashy Templates