Make a square with a diamond in the middle

Dear C++ Progreammer,

for a while I think about making a square with a diamond in the middle, if one of you have an idea about it, please look my design :

****++**** 8 * and 2 +
***++++*** 6 * and 4 +
**++++++** 4 * and 6 +
*++++++++* 2 * and 8 +
**++++++** 4 * and 6 +
***++++*** 6 * and 4 +
****++**** 8 * and 2 +

if you have any idea about it, please help me to solve this proble.

Regard and I'm waiting your source code :D
cout << "****++****" <<endl;
cout << "***++++***"<<endl;

and so on
I could give you the source code, but what would that help you? I'll give you mine when you show me your working solution. Hint: Break up the problem in its parts, and solve all of them individually.
fuadfauzi wrote:
I'm waiting your source code

Here you are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>

const char star='*';
const char plus='+';

template <int I>
struct StarCount;

template <> struct StarCount<0> { enum {Val=4}; };
template <> struct StarCount<1> { enum {Val=3}; };
template <> struct StarCount<2> { enum {Val=2}; };
template <> struct StarCount<3> { enum {Val=1}; };
template <> struct StarCount<4> { enum {Val=2}; };
template <> struct StarCount<5> { enum {Val=3}; };
template <> struct StarCount<6> { enum {Val=4}; };

template <int I>
struct PlusCount;

template <> struct PlusCount<0> { enum {Val=2}; };
template <> struct PlusCount<1> { enum {Val=4}; };
template <> struct PlusCount<2> { enum {Val=6}; };
template <> struct PlusCount<3> { enum {Val=8}; };
template <> struct PlusCount<4> { enum {Val=6}; };
template <> struct PlusCount<5> { enum {Val=4}; };
template <> struct PlusCount<6> { enum {Val=2}; };

template <char C, int IMAX, int I=0>
struct Print
{
    static void inline Run()
    {
        std::cout << C;

        Print<C,IMAX,I+1>::Run();
    }
};

template <char C, int IMAX>
struct Print<C, IMAX, IMAX>
{
    static void inline Run() {}
};

template <int IMAX, int I=0>
struct MainLoop
{
    static void inline Run()
    {
        Print<star,StarCount<I>::Val>::Run();
        Print<plus,PlusCount<I>::Val>::Run();
        Print<star,StarCount<I>::Val>::Run();

        std::cout << std::endl;

        MainLoop<IMAX,I+1>::Run();
    }
};

template <int IMAX>
struct MainLoop<IMAX, IMAX>
{
    static void inline Run() {}
};

int main()
{
    MainLoop<7>::Run();

    std::cout << "\n(hit enter to quit...)";
    std::cin.get();

    return 0;
}
r0shi, why so cruel today?
r0shi:
 
...();
Waow, thanks for your answer....

Thank's for m4ster r0shi too.

Hmm, what about make those shape consider to user input???
Topic archived. No new replies allowed.