/script>
WELCOME TO THE PROGRAMMING CHALLENGE THREAD. TODAY YOU WILL CREATE A FUNCTION OR PROGRAM THAT GENERATES A CHRISTMAS TREE WITH THE USER GIVEN LENGTH.
IF YOU DON'T COMPLY, THIS BIRD WILL STAB YOU
AS ALWAYS, HERE IS THE EXAMPLE./*
* christmas.cpp
* Created on: Sep 14, 2016
*/
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
char getRandomChar(){
int random = rand();
if((double)random/RAND_MAX > 0.75) return '@';
if((double)random/RAND_MAX > 0.5) return '*';
if((double)random/RAND_MAX > 0.25) return '#';
return '%';
}
int printtree(const int length) {
int width = 1;
int bottom = 0.1 * length;
char tree = '#';
for (int i = 0; i < length; i++) {
string temp = "";
if (width < 2) {
cout << right << setw(length + 1) << tree << endl;
} else {
for (int j = 0; j < width - 1; j++)
temp += getRandomChar();
cout << right << setw(length) << temp;
cout << tree;
cout << left << setw(length) << temp;
cout << endl;
}
width++;
}
if(bottom < 1){
cout << right << setw(length + 1) << tree << endl;
}
for (int i = 0; i < bottom; i++) {
string temp = "";
for (int j = 0; j < bottom - 1; j++)
temp += getRandomChar();
cout << right << setw(length) << temp;
cout << tree;
cout << left << setw(length) << temp;
cout << endl;
}
}
int str2int(const string &str) {
stringstream ss(str);
int num;
if ((ss >> num).fail()) {
return 10;
}
return num;
}
int main(int argc, char *argv[]) {
int length;
if (argc > 1) {
length = str2int(argv[1]);
} else {
length = 10;
}
srand(10983);
printtree(length);
return 0;
}
>>56598339
HERE'S THE OUTPUT OF THE EXAMPLE.
NOW GET GOING
>>56598463
gottem
o
t
t
e
m
>>56598421
> the trunk is also decorated
I don't trust you anymore
Does this count?
>>56598339
This could be a perfect example to show female-programmers how to "code" and the marvels of doing it...
>ooh it's so cute!... That's why we need more girls who code!...
>She made a Christmas tree made of ascii characters in a console application... we should hire her with top salary...