Classes Problem

Just as an initial note, this is NOT a homework problem. As you may know from my earlier posts, I have certain difficulties understanding classes. This was just a practice problem I picked up. Basically, I want to take input of 5 integers, and print like a bar graph of the sort (for say 1, 2, 3, 4, 5):
       
        *
      * *
    * * *
  * * * *
* * * * *


This is what I've done so far:
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<iostream.h>
#include<conio.h>

class PlotNumbers
{
	public:

	int p1, p2, p3, p4, p5, j, max;
	PlotNumbers();
	PlotNumbers(int, int, int, int, int);
	void Plot(void);
	void Fill();
	char plotter[5][15];
};

PlotNumbers::PlotNumbers()
{
	p1=3;
	p2=4;
	p3=3;
	p4=4;
	p5=3;
}

void PlotNumbers::Fill()
{
	max=(p1>p2)?p1:p2;
	max=(max>p3)?max:p3;
	max=(max>p4)?max:p4;
	max=(max>p5)?max:p5;

	for (int i=1; i<=5; i++)
	{
		for (j=1; j<=15; j++)
		{
			plotter[i][j]=' ';
		}
	}

	for (j=1; j<=p1; j++)
	{
		plotter[1][j]='*';
	}


	for (j=1; j<=p2; j++)
	{
		plotter[2][j]='*';
	}

	for (j=1; j<=p3; j++)
	{
		plotter[3][j]='*';
	}

	for (j=1; j<=p4; j++)
	{
		plotter[4][j]='*';
	}

	for (j=1; j<=p5; j++)
	{
		plotter[5][j]='*';
	}
}

void PlotNumbers::Plot(void)
{


	for (j=max; j>=1; j--)
	{
		for (int i=1; i<=5; i++)
		{
			cout<<plotter[i][j];
		}
		cout<<"\n";
	}
}

void main()
{

	PlotNumbers a;
	clrscr();

	a.Fill();
	a.Plot();

	getch();

}


My issues:
1) How do I take input from user for the parameters p1, p2, p3, p4, p5 using the same constructor name, but with different argument parameters, one being void (if user chooses default option) and of 5 ints (if user wants to enter his own ints)? When I try using Plotnumbers a(1, 2, 3, 4, 5), it doesn't compile.. Shows error of "Undefined symbol" or something...
2) This program works fine, but at the end of output, the compiler closes (I use TC++, I know, outdated, but still getting used to VC++, and am not very comfortable writing programs in that...) So any idea why this might be happening?

Thank you in advance! :)
Last edited on
1) define the different constructors separately. One taking 5 arguments and one that uses std::cin to read the variable values.

2) compiler normally closes as soon as compilation is over. There is no reason why it should stay running after it's finished?!
How do I define a constructor that takes input? Just can you give me an example please, just for the cin constructor... And any idea why my current constructor at line 10 doesn't function properly? When I declare a as:
PlotNumbers a(2, 3, 4, 3, 5);
It doesn't work...


And I mean, after the output, it usually goes back to the main screen where I can further edit my code. But now it just closes down, and I have to launch it again... I used the wrong term before... Just my compiler doesn't close, my IDE shuts down...
Here's my updated version of the program... Still need help as to why it shuts down, and why my above declaration of a doesn't work...

http://pastebin.com/GFcMfMhu
Because it hasn't been defined...

You declare two constructors: PlotNumbers(void) and PlotNumbers(int, int, int, int, int). You define the first one on line 17 (PB code), but you never define the second one. How would the compiler know what to do when he encounters a call to PlotNumbers(int, int, int, int, int)?
Ohk, got it! :D Thanks a lot... And any insight as to why my IDE crashes? Should I use VC++ only from now on? Can someone just teach me how to create a program, compile it and launch it in VC++? Or maybe direct me to a good tutorial perhaps? Or maybe suggest a quick simple compiler? Coz I am not very concerned with .exe files.. I just want to practice C++, for which I need a good, updated and quick compiler... Any such software available? Do direct me, I shall be very thankful! :) :)
Also, if someone could just give me some more practice problems of the sort, or maybe suggest a certain type of programs (such as text based games or something), that use classes... Coz I really want to grasp this concept, and then move on to higher concepts like vectors and deques (I don't know what they even are! Just have seen the terms on the forums)...
Topic archived. No new replies allowed.