bhoot_jb 47 Junior Poster in Training

@ salem :
thank you for the reference. :)

@ marco93 :
i never said i have problem with C++ and Win32 API..Its just that i didnt like using MFC. I love both C and C++. So i definitely wont have any problem with C++ and Win32 API. :)

@ laiq ahmed :
sure. I will give them a try :)

bhoot_jb 47 Junior Poster in Training

After using MFC, I felt like throwing it away. I thought to move on to Win32 API programming (I work on Windows platform.)
But then, it is all C. I dont say i dont like C, but is there any better OO alternative to MFC for Win32 platform? Or should i make my own classes from API ,whenever required?

bhoot_jb 47 Junior Poster in Training

If you want only a single string, then its getline().

If you want several strings, then a single array certainly wont do. I wonder how will you differentiate between strings. As you said, if you use '.', still wouldnt it be better if you use a 2-D array of characters, or an array of character pointers?

bhoot_jb 47 Junior Poster in Training

Your information isnt enough, I guess. Though your question seems simple enough, this line depicts somthing else which i dont know :
> double a=(h[0]*b[1])+......

First of all, clear your question, or post some code.

bhoot_jb 47 Junior Poster in Training

well, i am quite confused here. You mean to say you want to take input of several strings in a single character array? :|

infact, here you are asking for a single character everytime :
> cin >> a

if you meant to count the number of characters, then you may do it using some function like strlen(), or you may put a counter along with input.

Also, the array here is certainly unstable, without '\0' null character.

bhoot_jb 47 Junior Poster in Training

Nvm, I was going about it wrong. I figured it out. Here's what I have:

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int even = 0, odd = 0, dig, num;

	cout << "Please enter a list of numbers (ex. - 12345)" << endl;
	cin >> num;

	while (num > 0)
	{
		dig = num % 10;
		num = num / 10;
		
		if(dig % 2 == 0)
			even = even + dig;
		else
			odd = odd + dig;
	}

	cout << "The sum of the even integers is: " << even << endl;
	cout << "The sum of the odd integers is: " << odd << endl;

	return 0;
}

Thanks for the help :)

what is quite confusing is the 'num' integer.
You said that you are taking input of a list of integers while you have just asked for a single integer.
I assume that you have taken the input of "list of integers" in a single integer 'num' itself, i.e., you have considered the value of 'num' as a list of integers (digit by digit) :|
if this is what you have assumed, i think this is a wrong approach. You would have rather used an array. :)
Think upon it.

bhoot_jb 47 Junior Poster in Training

differences ? :)
i think it would suffice to say that TC++ is one of the ancient compilers for C/C++ while VC++ is one of the modern compilers (infact, IDE) for C/C++ applications.

I think you are asking so because TC++ was/is being used in your college/school. :P
I guessed so because we are still required to work with that age-old compiler. :|

Anyways, basically, the coding standards remains mostly the same, i refer to the syntax and all that. However, the structure of the code does differ in both. Also, .H files certainly cannot be avoided. VC++ also includes files of other types, which you can know only if you go through the stuffs by yourself. :)

bhoot_jb 47 Junior Poster in Training

salem answered it for me. :)
well my code snippet was just a code written in haste. :)
the line you doubted was a missing line.
As Salem said, you will have to advance by yourself. There is no way the while() could do it for you.
The advancement can either be :

current = current->link;

in the while(current!=NULL) loop or you can replace the whole while() loop with a for() loop as demonstrated by Salem.

bhoot_jb 47 Junior Poster in Training

I think you have used too many pointers here. You can manage with a few.

> valueOfNode = temp1->next->value;

i got confused in this line, because earlier you had declared a node :
> node *next;
is this 'next' you are referring ? or is it the link of temp1 to the next node?

current = H;       //current points to the first node of H.
oddStart = H1;   // oddStart points to the first node of H1.
node* newnode; // for a newnode.
while (current != NULL)
{
   nodeValue = current->value;
   if ( nodeValue % 2 != 0)
   {
      if (oddStart == NULL)
      {
         oddStart = new node;
         oddStart->value = nodeValue;
         oddStart->link = NULL;
      }
      else
      {
         temp = oddStart;
         while (temp->link != NULL)      // here 'link' is the link to the next node.
             temp = temp->link;
         newnode = new node;
         newnode->value = nodeValue;
         temp-> link = newnode;
         newnode->link = NULL;
      }
   }

i think this code should work for you. However, it would contain mistakes. But i just want to convey that you can cut down the use of pointer variables to a great extent. The rest is upon you. :)

bhoot_jb 47 Junior Poster in Training

the first challenge for you is to read and understand the instructions that are required to be followed here.

bhoot_jb 47 Junior Poster in Training

dude! you need to find some other place; no one here will help you.
best luck with your 'assignment'.

bhoot_jb 47 Junior Poster in Training

> C++ is a OO oriented version of C.
>> That's a rather naive perspective. C++ is multi-paradigm, meaning it isn't just object oriented, or generic, or procedural, it's all of them, depending on your tastes and needs.

You are right. I just meant to emphasize on the prime and major use of C++, which i think is OO and generic programing.

bhoot_jb 47 Junior Poster in Training

You should rather refer to some good book inorder to remove the elementary confusions.
C++ is an object-oriented version of C.
You can also call it as an enhanced version of C (just in regard to syntax and keywords) .
However, as far as coding style matters, only certain syntactic similarities remain - such as loops. Otherwise, C++ possesses a whole new concept of data encapsulation, inheritance, generic programming, etc., which C certainly doesnt provide.

bhoot_jb 47 Junior Poster in Training

what ancient dragon said is correct. Your code isnt formatted at all. First of all, you need to learn that.

I would like to point out certain things though.

First of all, you need to decide which language you actually want to use - C or C++. It seems that you have included the iostream.h (a C++ header) file just to use 'cin' and 'cout'.

Also, i would like to point out the use of 'void main()' - The experts here had had warned me against using it. I am doing the same to you for just reasons. :)

bhoot_jb 47 Junior Poster in Training

i think first of all you really need to attempt it by yourself. People here will help you only if you have made some honest attempt :)

Salem commented: Well said +22
bhoot_jb 47 Junior Poster in Training

>i mean to say that arrays are treated internally as pointers.
No, arrays are treated internally as arrays. Please don't make the mistake of thinking that arrays and pointers are the same. They're not, and slippery slopes lay waiting for the people who disagree.

>Hence, both the following lines hold true inorder
>to access value at i(th) postion in arr[6]: a or *(a+i)
Your statement is correct (assuming a stands for arr or a pointer to the first element of arr). I don't agree with the "hence" part though, because a[i] and *(a+i) are both acting on a pointer. Except for three specific cases, the name of an array is converted to a pointer to the first element of the array. That means a[i] is functionally equivalent to this:

// a[i]
( (int*)&a )[i]

And as you're vaguely aware, the array notation is syntactic sugar for a pointer offset calculation. The above is converted internally to this:

*( (int *)&a + i );

Ok. thanks for pointing out my mistake; and as far as "a" is concerned it was my mistake.
I actually meant :

arr[i]
*(arr+i)

:)

bhoot_jb 47 Junior Poster in Training

Thanks, Bhoot,

I think I could reduce my pointer headaches if only I could understand pointers better.

I'm trying to think about this conceptually. Somewhere in memory I've declared a character array (not an array of individual characters, but an array of variable length strings made up of characters) and I want to point to a given element of that array, i.e., to one of those strings, name[0] through name[4], and then extract that character string and place it in a character string variable.

Intuitively I know this is possible. I'm just not getting it. But thanks again for your observations.

hmm..OK. Let me help you with some explanations.
I am sure you know that basically a pointer points to some variable. and int* will point to an integer.
Now consider the following array :

int arr[6]

The above can also be declared as :

int* arr;
arr = new int[6];

i mean to say that arrays are treated internally as pointers. Hence, both the following lines hold true inorder to access value at i(th) postion in arr[6] :
a or *(a+i)

both the above expressions mean the same thing.

If you talk about 2-D array, they can also be handled by either using an array of pointers (as you have used) or a pointer to an array; or the simplest is to use the 2-D array itself.
:)

bhoot_jb 47 Junior Poster in Training

lolz i agree with niek_e :D
if your first step in programming world is to build an OS, then only God knows what your next step would be. :)
well, i am not discouraging you alex. But its a very long way you have to walk before you can really do any such thing. :)

and regarding your memory issue, i would like to shed some light. I hope it would help you. :)

Memory is something which is "hardwired". Consider RAM or hard disk. These are where your data would be saved.
Consider RAM. The function of OS is to manage the memory of RAM. It allocates the required part of RAM memory to the desired process. Later, when the process is done with that allocated memory, it 'informs' OS and OS, in turn, deallocates the memory.
Now, here allocating memory means that particular chunk of memory CANNOT be used by any other process. When such a memory is deallocated, the memory again becomes free,i.e, it can be used by some other process.
Thus, you should rather use 'allocation' and 'deallocation' than 'creation' and 'destruction'. :)
In C++, if you dont use 'new' operator, OS wont know how much memory to allocate to the object. Hence, the object will use any random block, which may be overwritten by any other process, thus crashing down your whole program.
When you use new, you request OS to allocate the memory. Obviously you …

bhoot_jb 47 Junior Poster in Training

A comment if I may bhoot_jb.


You make heavy use of [..]. I know what ellipsis are [...], but I can't figure what's the process that warrant the use of two consecutive periods.


What's the advantage of misspelling "good" to just save the writing of one more vowel?
Why not "gu luc"? That seems to me more advantageous. Better yet, "guluc" will save even the space.
Of course, all is for naught because of the mysterious two periods afterward.

lolz. OK. thanks for pointing out my mistakes. Actually i was used to such typing in this weird way in mobile chatting. :) There is nothing special about using two consecutive periods or ellipsis. :)
And as far as "gud luck" is concerned, its almost the same issue, i.e., i make a heavy use of short spellings. :| i have been warned earlier against using such short spellings.
However i have improved much better and will do the same in future. :)
Now, this is going off-topic. So i better conclude. :)

Aia commented: For taking it the right way. +9
bhoot_jb 47 Junior Poster in Training
Selected Name: ", STRLEN, name_num );

this line dint make much sense to me. :|

anyways..talking about your problem..

name_sel = *name [ name_int ];

this wont work at all. You are assigning a character to a character array. that seems illogical.
*name[name_int] actually yields the first character of the name_int(th) string (name here) in the array.

as ancient dragon said..you will have to make use of a pointer judiciously...
else you may use strcpy()...that would be an easy solution..if you dont want to take the headache of pointers.. :)
gud luck... :)

bhoot_jb 47 Junior Poster in Training

well...this thing also depends on how the menus and submenus are structured.
For example...i have faced a situation in which..i need to first select an object on which i need to perform certain operations...which are,in turn, same for all the objects..
Thus, i would definitely have a structure..in which..i have the main menu which gives options to select an object..and then i move to another menu (which i may/ may not consider submenu) which gives choices for the operations.. :)

another situation is obvious..which..i think you are facing..

anyways..i have attached a program which deals with both the situations..
have a look on it if u want to. :)
NOTE : its a CPP (and hence an OO) program..Also the graphics.h header file of Borland Turbo C++ i have used is very much primitive..so i think the code wont work..unless you use Turbo C++...
however..i dont think thats your concern...so hope this helps you.. :)
gud luck..

bhoot_jb 47 Junior Poster in Training

I have been given an assignment to simulate MS Paint application.
I am much confused if to use document-view architecture or go without it (i will certainly use MFC..a necessity of our syllabus :| )

Also where exactly should i use/avoid document-view architecture?
waiting for a reply ... :)

bhoot_jb 47 Junior Poster in Training

@ArkM :
okies got your point...

@beyond :
yupp..you are right...it was just that i hadnt checked the code yet...so didnt find out that thing.. :)

bhoot_jb 47 Junior Poster in Training

@ArKM :

bhoot_jb 47 Junior Poster in Training

i am writing a program on 2-D transformation which handles transformations for three objects, namely, point, line and a triangle.
i have created a base class Object and derived three classes - Point, Line, Triangle - from it.
Here i will discuss just the Object and Point class.
The code snippet for that is as under :

// base class Object
class Object
{
	public :
		virtual void translate() = 0;
//		virtual void rotate() = 0;
//		virtual void scale() = 0;
//		virtual void reflect() = 0;
//		virtual void shear() = 0;
		virtual void draw(void) const = 0;
		virtual void setCoords() = 0;
};


// Point class
class Point : public Object
{
private :
	int* coords_;

public :
	Point()
	{
		coords_ = new int[2];
	}

	~Point()
	{
		delete coords_;
	}

	void setCoords (int*& coords)
	{
		coords_[0] = coords[0];
		coords_[1] = coords[1];
	}

	void translate (const int tx, const int ty)
	{
		coords_[0] = coords_[0] + tx;
		coords_[1] = coords_[1] + ty;
	}

	void draw(void) const
	{
		putpixel (coords_[0], coords_[1], GREEN);
	}

};

however, the compile complains me when i compile this code saying that i cant create an object of the abstract class Point, which i think is correct because i think i have actually performed overloading rather than overriding..hence the compiler throws me this error..
Now my actual problem is how to overcome this problem. I require to keep the methods like translate(), draw() as purely virtual in the base …

bhoot_jb 47 Junior Poster in Training

>>or am i just exaggerating this thing?
You are misunderstanding the difference. The presence of a lot of member functions has nothing to do with efficiency. If you just want to use structures and pure win32 api then IMO write a C program, not C++.

MFC itself is pretty in-efficient. Its a handy set of c++ classes, but not very efficient. So to quibble about the difference of using RECT or CRect isn't really very productive. If your program requires efficiency and speed, then ditch MFC and use something else, such as wxWidgets.

ohkk...i got your point..thanks for guidance.. :)

bhoot_jb 47 Junior Poster in Training

IMO use MFC objects when available. In the two cases you cited it doesn't really matter to the compiler, it just makes your program more consistent if you use the MFC objects.

ok..but i doubt one thing..doesnt efficiency affect here? i mean using a structure and using a class with lots of member functions - both are different thing..or am i just exaggerating this thing? :|

bhoot_jb 47 Junior Poster in Training

i am currently learning VC++ with MFC. But i am quite confused now. My dilemma is whether to use structures (which i guess are used extensively at Win32 API level) or their equivalent MFC objects.
let me elaborate it. For example i want an array of points to use it somewhere. I gathered that i have two options to do so - either to use POINT structure array or array of CPoint objects. Now, which one should i use?
Being MFC programming should i stick to CPoint or should i take the liberty to use POINT array? Note that i dont have any use of supposed member functions of CPoint in case if i should use it..
Same goes with some other things like RECT and CRect.
So please throw some light on this.. :|

Another question :
i am also quite confused with the use of GDI function ::GetStockObject(). Being a non-MFC function (i guess so), i think it shouldnt be used much around an MFC code.
But i need to use it at certain points like :

Frame::Frame()   // Frame::CFrameWnd class
{
   HBRUSH brush;
   brush = (HBRUSH) ::GetStockObject (WHITE_BRUSH);
   LPCTSTR className;
   className = AfxRegisterWndClass (NULL, AfxGetApp()->LoadStandardCursor(IDC_CROSS),
brush,
AfxGetApp()->LoadStandardIcon(IDI_ERROR));

   Create (className, "XYZ");
}

i think the another way might go like this (using CBrush):

Frame::Frame()
{
	defaultCursor_ = AfxGetApp()->LoadCursor (IDC_CURSOR1);
//	defaultBrush_ = (HBRUSH) ::GetStockObject (WHITE_BRUSH);
	defaultIcon_ = AfxGetApp()->LoadStandardIcon (IDI_ERROR);

//     here defaultBrush_ is  : CBrush defaultBrush_;
        defaultBrush_.CreateSolidBrush(RGB (0,0,255));
	HBRUSH …
bhoot_jb 47 Junior Poster in Training

Don't use window styles there, instead specify a combination of class styles, see http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx#class_styles

:D
bro...thank you so much..this problem had eaten my head off since a day and a half.. :(
:@
but you solved it out.. :)
i even went to the point of replacing some dlls in system...lolz...
because the people at Microsoft advised to do so for this error... :@
anyways ..thank you so much again... :)
:D

bhoot_jb 47 Junior Poster in Training

i am a beginner in MFC programming and using MS VC++ 6.0. I am trying to create my own window using AfxRegisterWndClass(). My code is as follows :

Frame::Frame()
{
	LPCTSTR className;
	HBRUSH brush;
	brush = (HBRUSH) ::GetStockObject (BLACK_BRUSH);
        className = ::AfxRegisterWndClass (WS_OVERLAPPEDWINDOW,         AfxGetApp()->LoadStandardCursor (IDC_CROSS),
brush,
AfxGetApp()->LoadStandardIcon (IDI_ERROR));
	Create (className, "BHOOT");
//	Create (NULL, "Bhoot", WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL, 0, NULL);
}

The above code segment shows the constructor of Frame class, the class derived from CFrameWnd. Also, FYI, i havent used document/view architecture.
Now, my problem is when i run my code, i meet with an error saying :
" This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for further information."

however, when i dont register my own window class and rather proceed with a frame using CWnd::Create() function, i dont face any such error.

can anyone throw some light on my problem.?? :|

bhoot_jb 47 Junior Poster in Training

i am currently working with VC++ 6.0. i have just begun with it and wrote my first non-MFC code in it..however i have faced a problem in which my program terminates immediately on executing it..and i mean immediately..it doesnt even show the window that i create through that program..
however..later on i tested the ready made "Hello World" code..when i ran that code it worked fine and well...without any problem..
i dont know where i am stuck...my code is as follows :

#include <windows.h>

LRESULT CALLBACK WinProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain (HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszCmdArgs, int nWinMode)
{
	MSG Msg;
	WNDCLASS WinClass;	
//	WNDCLASSEX WinClass;
	HWND hWnd;
	
	WinClass.hInstance = hThisInst;
	WinClass.lpszClassName = "Bhoot";
	WinClass.lpfnWndProc = WinProc;
	WinClass.style = 0;
//	WinClass.cbSize = sizeof (WNDCLASSEX);
	WinClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

	if (!RegisterClass (&WinClass)) 
		return 0;
	
	hWnd = CreateWindow ( "Bhoot", "Bhoot", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hThisInst, NULL);
//	hWnd = CreateWindowEx ( NULL, "Bhoot", "Bhoot", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hThisInst, NULL);
	ShowWindow (hWnd, nWinMode);
	UpdateWindow (hWnd);

	while ( GetMessage ( &Msg, NULL, NULL, NULL))
	{
		TranslateMessage (&Msg);
		DispatchMessage ( &Msg);
	}

	return Msg.wParam;

}


LRESULT CALLBACK WinProc ( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch (Msg)
	{
		case WM_DESTROY :
			PostQuitMessage (0);
		break;

		default :
			return DefWindowProc (hWnd, Msg, wParam, lParam);
	}
	return 0;
}

can anyone explain me the reason and the solution to it?? :|

bhoot_jb 47 Junior Poster in Training

well..my problem is i cant find crystal report in my vb6. And yes..i have also checked the so famous path :
common\tools\vb..
but the thing is i had to stop right after accessing tools folder..couldnt find vb itself.
is there any solution to my problem? :(

bhoot_jb 47 Junior Poster in Training

i am trying to install VS6 but it is giving following error.

setup has encountered a problem in launching the followning command line:
"wpie15.exe" /q:a/r:n.
if you have a system directory that contains a % sign, or the directory names *starts* with a space (i.e. 'C:\win95\system'), then setup will fial. please restart setup and ensure your system directory names does not contain the aforementioned problems, setup will now abort...

but i could not find any such directory with a % sign or space ...can anyone solve my problem asap?

bhoot_jb 47 Junior Poster in Training

i am trying to install VS6 but it is giving following error.

setup has encountered a problem in launching the followning command line:
"wpie15.exe" /q:a/r:n.
if you have a system directory that contains a % sign, or the directory names *starts* with a space (i.e. 'C:\win95\system'), then setup will fial. please restart setup and ensure your system directory names does not contain the aforementioned problems, setup will now abort...

but i could not find any such directory with a % sign or space...can anyone solve my problem asap?

bhoot_jb 47 Junior Poster in Training

Hi,

I guess, it must have been installed in your system.
In VB Editor check menu:
AddIns >> Report Designer

REgards
Veena

okies... :)
thnxx... :)

bhoot_jb 47 Junior Poster in Training

Hi,

Yes, I know, its a Standard Export Invoice Format. I have designed it using CR. Well the Top Portion Goes into Page Header. Place Lines/Boxes etc..
And Place the Detail Fields (Qty / rate) in Detail Section.

Regards
Veena

:D
thank you so much dear..you have almost solved my problem... :)
now can you tell me where do i get this crystal report..?? :|

bhoot_jb 47 Junior Poster in Training

Hi,

Use Crystal Report. Design the Report using all the Lines and Boxes. Connect to the Database. Insert the Table where all the Details are stored. Place the Fields in Respective Columns.
Now from VB, Show the CR..

Regards
Veena

hey veena..would it solve my problem - printing the report in the format i want..and let me tell you the format is quite irregular : tabular but quite irregular...the format is given in the document which i attached along with my question..please check it out if u havent..and reply me... :)

bhoot_jb 47 Junior Poster in Training

Hi,
I am also having this problem. but i solved this using Printer.PaintPicture. To print invoice, you draw lines and text in any picture box then use this Printer.PaintPicture Method to print the invoice. The picture box or form you are using to draw invoice must represent the real unit. For example picture box width and height should be equal with the paper width and height.

One more thing, For drawing text, PictureBox.Print may not be useful. Instead use DrawText() API.

err...umm...can you provide me any sample code of this .paintpicture thing? :|

bhoot_jb 47 Junior Poster in Training

i think it is not possible to print vertical lines along with text data in vb6..so i thot of transferring the whole contents from vb form to a word document. but now i dont know how to do that. i want to transfer the data in a specific tabular format. still the format is too irregular to be in excel..so can anyone provide me a solution to this question? :|
i have attached the format to be used. It is to be noted that the data is to be taken from vb.

so please help me.. :|

bhoot_jb 47 Junior Poster in Training

i am working on a vb project in which need has arised to print an invoice. however the problem is that the contents of the invoice is accompanied by horizontal and vertical lines. Also the so-formed rows and columns are not regular. My question is how can i print such a form. I mean the printout should also have the horizontal and vertical lines along with the data.
i have attached the desired format along with this post. Please take time to view it.
Can anyone give me some solution..other than printform ... :|

bhoot_jb 47 Junior Poster in Training

I have used the Package & Deployment Wizard to put my Visual Basic Program on CD, I then copied over my database 'calculations.mdb' onto the cd also so that the VB program can access the database when installed on another PC. However, the program still searches the same path as it does on my computer when trying to open the database whereas i would obviously like it to search for it wherever the user installs it. Is it possible to hardset this in my VB code? This is what it is set to at the moment:

conconnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "" & "calculations.mdb;Mode=Read|Write"

Does anyone know how I can adapt it? If not, is it possible to set it to search on the CD in the disk drive?(although this would be awkward as the user would have to keep the cd in there but better than nothing!)

bhoot_jb 47 Junior Poster in Training

in my application, i have created a data environment. Then i have connected a data grid to that data environment. Now my problem is when i add or delete one or more records, then the database updates itself...but the datagrid doesnt....it doesnt update until i run the application again... :(
how do i update or refresh the datagrid?
please help me if anyone has got a solution to this problem...

bhoot_jb 47 Junior Poster in Training

If you want to add those details, go to Project-->Add Form and select About Dialog. Specify the information there and link it with the menu option Help-->About in your application using menu editor.

err...i think u have mistaken my question...actually...suppose the application requires to ask a compnany name, contact no., etc. from the user while installing the application itself..i mean while running the setup...now i am not getting how to integrate this form (or whatever..) in the setup itself...please guide me now.... :|

bhoot_jb 47 Junior Poster in Training

in my project, i need to take some details like company name, contact no. and address during the installation of the project itself.
but i dont know how to accomplish that..please guide me. :|

bhoot_jb 47 Junior Poster in Training

I tend to think with pointers because I started with C...and pointers are commonplace in C...and thats how I learned...lol. But my thoughts were this: the elements in a stack may in fact be objects themselves (i.e. their own stack structures), so I thought it would be easier to manipulate if you were pointing to the element instead.

I'm sure it can be done without pointers, but that I shall leave as an exercise instead for you.

Besides, pointers are a wonderful and powerful (or scary..) part of the language...if you aren't going to use them, switch to Java (or C# if you are a Windows-only programmer ;) ). lol (just kidding) :)

lolz...got your point...actually even i have upgraded from C to C++...so am used to pointers...but here i just wanted to try it out first with simple variables...and then to use pointers...nevertheless...thank u for your response... :) :D

bhoot_jb 47 Junior Poster in Training

I have a potential solution...though you may not like it (and I haven't fully implemented it, so there could be some leaks):

1) In your stack class, in the private field, in the node struct, change T element to be a pointer (i.e. T *element)

2) In the public field of the stack class, change your prototype for push to take T* as a parameter, and change the pop prototype to return T*.

3) In the push implementation, change the function header to accept T *ele as a parameter.

4) In the pop implementation, return type should be T*, change T popped to T* popped.

5) In the view implementation, dereference temp->element (i.e. *temp->element).

6) In main, you can set up your stacks as follows:

stack <int> *subs = new stack<int>;
stack <stack<int>> *mains = new stack<stack<int>>;

To push elements to the subs stack:

int a = 5;
int b = 10;

subs->push(&a);
subs->push(&b);

To push elements to the main stack:

mains->push(subs);

However, I didn't know how you wanted view to behave for main...To view the top stack in main you can do this:

mains->pop()->view();

Anyway, I didn't check all the implementations, so some things might need to be changed...and this may not be what you were looking for...and you might have to write a few extra things...dunno

hey yaaa..i got your point...but i would like to know the reason why you are emphasizing on using pointer here...

bhoot_jb 47 Junior Poster in Training

i am writing a code for a stack within stack...or nested stack...whatever..
in the code..and the mainstack is a stack of substack, which in turn, is a stack of integer data..

i thought of using class template for both the stacks - mainstack and substack..but am confused with how to use it..
the code for the template is as under :

template <class T>
class stack
{
	private :
		struct node
		{
			T element;
			node *link;
		} *top;

	public :
		stack();
		~stack();
		void push (T ele);
		T pop();
		void view();
};

template <class T>
stack<T> :: stack()
{
	top = NULL;
}

template <class T>
stack<T> :: ~stack()
{
	node *destroy;
	while ( top != NULL)
	{
		destroy = top;
		top = top -> link;
		delete destroy;
	}
}

template <class T>
void stack<T> :: push (T ele)
{
	node *newnode;
	newnode = new node;
	if (newnode == NULL)
	{
		cout << "Stack overflow!" << endl;
		return;
	}
	newnode -> element = ele;
	newnode -> link = top;
	top = newnode;
}

template <class T>
T stack<T> :: pop()
{
	if (top == NULL)
	{
		cout << "Stack is empty." << endl;
		return NULL;
	}
	T popped;
	popped = top->element;
	node *temp;
	temp = top;
	top = top -> link;
	delete temp;
	return popped;
}

template <class T>
void stack<T> :: view()
{
	node *temp = top;
	while (temp != NULL)
	{
		cout << temp->element << endl;
		temp = temp -> link;
	}
}

however my …

bhoot_jb 47 Junior Poster in Training

i am writing a code for a stack within stack...or nested stack...whatever..
in the code..and the mainstack is a stack of substack, which in turn, is a stack of integer data..

i thought of using class template for both the stacks - mainstack and substack..but am confused with how to use it..
the code for the template is as under :

template <class T>
class stack
{
	private :
		struct node
		{
			T element;
			node *link;
		} *top;

	public :
		stack();
		~stack();
		void push (T ele);
		T pop();
		void view();
};

template <class T>
stack<T> :: stack()
{
	top = NULL;
}

template <class T>
stack<T> :: ~stack()
{
	node *destroy;
	while ( top != NULL)
	{
		destroy = top;
		top = top -> link;
		delete destroy;
	}
}

template <class T>
void stack<T> :: push (T ele)
{
	node *newnode;
	newnode = new node;
	if (newnode == NULL)
	{
		cout << "Stack overflow!" << endl;
		return;
	}
	newnode -> element = ele;
	newnode -> link = top;
	top = newnode;
}

template <class T>
T stack<T> :: pop()
{
	if (top == NULL)
	{
		cout << "Stack is empty." << endl;
		return NULL;
	}
	T popped;
	popped = top->element;
	node *temp;
	temp = top;
	top = top -> link;
	delete temp;
	return popped;
}

template <class T>
void stack<T> :: view()
{
	node *temp = top;
	while (temp != NULL)
	{
		cout << temp->element << endl;
		temp = temp -> link;
	}
}

however my …

bhoot_jb 47 Junior Poster in Training

I can't, but I can explain. A vector is a sort of an array which can grow and shrink on the fly. In this example I use std::vector<int> to indicate I'm going to store ints in it.

Now for the somewhat harder part.
The map contains a string and a vector of ints. The string is sort of it's ID. The vector the contents:

ohkk...got it now...actually i knew the vector...but not the map...but its clear now... :)
thanks for help... :)

bhoot_jb 47 Junior Poster in Training

Yeah....whatever.
Please read the rules (part: keep it clean)

How about you use a vector for your 'mini-stack' and then make a map of vectors for your big (stack-)stack

Since if written this samplecode already for someone else:

std::map <std::string, std::vector<int> > array;
  array["v1"].push_back(1);
  array["v1"].push_back(13);
  array["v1"].push_back(344);
  array["v2"].push_back(344);

  cout << "The map 'array' has " << array.size() << " vector(s)\n";
  cout << "The vector v1 in map 'array' has " << array["v1"].size() << " numbers\n";

ok...yaaa...got it...sorry...wont repeat that mistake... :) ....net chat... :)
and umm...i didn't get much of your code...if you can simplify it... :|