Diamond Class. Please Help

Pages: 12
Sorry for later response, I just got out of class, but yes the code works and looks good! Thank you! I didn't mean to make you do all that extra work! I have the rest of my code that looks good, all i was missing was drawing the diamond in the
void diamond::draw()

The only issue though is for like diamond d(7) I need the 7 to be just one side of the quadrilateral, not both.

So if i inputed d(7) then I would need 7 characters that print out for each side. I.E the area should then be 7 * 4 = 28.

not 4 * 4 = 16

how would the code change to implement that change??
like if you input 6, then it should print out like this, and also there should be spaces between the borders and fill characters too

     ^ 
    ^ ^
   ^ * ^
  ^ * * ^
 ^ * * * ^
^ * * * * ^
 ^ * * * ^
  ^ * * ^
   ^ * ^
    ^ ^
     ^ 
If you do it the way I've suggested, these changes will be very easy.
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
#include <iostream>
using namespace std;

class diamond{
	
	private:
	int size;
	public:
		diamond(int s){
			size=s;
		}
	void draw(){
		//int size=size;// it ssizeould be odd;
		int h=2*(size-1);
	   int w=h/2; 
	   int k=0; 
     for(int i=0;i<=h;i++)
   {  
           
		 
		  if(i>w) {k=h-i; }else{k=i; }

   	 for(int j=0;j<=h+1;j++){
         if(j==w-k or j==w+k+1){cout<<"# ";j=j+1;}
		 if(j>w-k and j<k+w-1){cout<<"* ";j=j+1;}
		 if(j<w-k or j>w+k  ){cout<<" ";}
		 
		 
		       	
        }
    cout<<endl;
   	 }

		
	}
	
};

int main()
{
diamond d{6};
d.draw();
   	
   	   return 0;
}
Last edited on
It worked!!!!
You have no idea how much I appreciate this! Really! Seeing it actually be right on my screen has been the highlight of my day! Thank you so much again for working with me. It means a lot! How long have you been programming in C++?
last 5/7 years not programming cpp. overall i programming in diff lang near about 13yrs.
Topic archived. No new replies allowed.
Pages: 12