Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
#include <iostream>
2
#include <iomanip>
3
#include "termmanip.h"
4
#include "rectangle.h"
5
6
using namespace std;
7
8
9
void
10
rectangle::draw() { //draw the rectangle
11
if(height == 0 || width == 0) return; //skip empty rectangles
12
13
//draw the top and bottom
14
cout << cursorPosition(tx, ty)
15
<< setw(width) << setfill('#') << '#';
16
cout << cursorPosition(tx, ty+height-1)
17
<< setw(width) << setfill('#') << '#';
18
19
cout << setfill(' ');
20
21
//draw the sides
22
for(int i=0; i<height-2; i++) {
23
cout << cursorPosition(tx, ty+i+1) << '#' << setw(width-1) << '#';
24
}
25
26
cout.flush(); //push to the screen
27
}
28
29
void
30
rectangle::getUserParameters(int firstLine) {
31
//get our parts from the user
32
cout << cursorPosition(1, firstLine) << "X: ";
33
cin >> tx;
34
cout << cursorPosition(21, firstLine) << "Y: ";
35
cin >> ty;
36
cout << cursorPosition(1, firstLine+1) << "Width: ";
37
cin >> width;
38
cout << cursorPosition(21, firstLine+1) << "Height: ";
39
cin >> height;
40
}
41
42