/script>
[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Programming challenge

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 6
Thread images: 3

File: birdmin.jpg (163KB, 800x600px) Image search: [Google]
birdmin.jpg
163KB, 800x600px
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;
}
>>
File: OUTPUT.png (31KB, 500x649px) Image search: [Google]
OUTPUT.png
31KB, 500x649px
>>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
>>
File: z.png (43KB, 1040x807px) Image search: [Google]
z.png
43KB, 1040x807px
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...
Thread posts: 6
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.