Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Languages
Assignment # 02
Raja Roshaan
Programming Fundamentals
BS (CS) (B)
Shapes
CODE:
#include <iostream>
using namespace std;
void righttriangle() {
int size = 0;
cout << "Enter size: ";
cin >> size;
for (int x = 0; x < size; x++) {
cout << "\t\t";
for (int y = 0; y <= x; y++) {
cout << "*";
}
cout << endl;
}
cout << "\nDone" << endl;
}
void pyramidtriangle() {
int size = 0;
cout << "Enter size: ";
cin >> size;
for (int x = 0; x < size; x++) {
cout << "\t\t";
for (int gap = 0; gap < size-x; gap++) {
cout << " ";
}
for (int y = 0; y < (2 * x - 1); y++) {
cout << "*";
}
cout << endl;
}
if (x == 1 || x == length) {
cout << "*";
}
if (x > 1 && x < length) {
if (y == 1 || y == width) {
cout << "*";
}
else {
cout << " ";
}
}
}
cout << endl;
}
cout << "\nDone" << endl;
}
void hollowtriangle() {
int size = 0;
cout << "Enter size: ";
cin >> size;
for (int x = 0; x < size; x++) {
cout << "\t\t";
for (int gap = 0; gap < size - x; gap++) {
cout << " ";
}
for (int y = 0; y < (2 * x - 1); y++) {
if (y == 0 || y == 2 * x - 2 || x==size-1) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
}
cout << endl;
}
cout << "\nDone" << endl;
}
void characterX() {
cout << "Enter size: ";
int size;
cin >> size;
for (int x = 0; x < size; x++) {
cout << "\t\t";
for (int y = 0; y < size; y++) {
if (x == y || y==size+1-x-2) {
cout << "*";
}
else {
cout << " ";
}
}
cout << endl;
}
cout << "\nDone" << endl;
}
int main() {
char redo = 'y';
do {
cout << "Select the shape you want to draw:\n1. Right Angle Triangle\n2.
Triangle\n3. Hollow rectangle\n4. Hollow triangle\n5. Character C\n6. Character
X\nEnter your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
righttriangle();
break;
}
case 2: {
pyramidtriangle();
break;
}
case 3: {
hollowrectangle();
break;
}
case 4: {
hollowtriangle();
break;
}
case 5: {
characterC();
break;
}
case 6: {
characterX();
break;
}
default: {
cout << "Invalid choice" << endl;
break;
}
return 0;
}
OUTPUT: