Agni 370 Practically a Master Poster Featured Poster

what he meant was
base* b = new child();

then push_back(b) into the vector.

however for dynamic polymorphism you should keep functions which need to be derived from base class as virtual, so that when you call them with the base class pointer it calls the correct child class function.

so basically you need to read about polymorphism and 'dynamic' polymorphism in particular.

Agni 370 Practically a Master Poster Featured Poster

you can do that, no issues but your example is not the best one. If its the same object you might as well use the 'this' pointer. You can try looking at some standard copy constructor declarations. probably the most basic and important use of a const object reference.

Agni 370 Practically a Master Poster Featured Poster

if you want more details let us know which compiler or IDE you are using. if someone here has used that you might get the exact ans and explanation.

Agni 370 Practically a Master Poster Featured Poster

They are declared in the parameter list so that you can pass address to the function. if you declare them as local variables inside the function how will you pass the address of the variables to that function?

mainly it depends on the requirement where and how you use pointers.

Agni 370 Practically a Master Poster Featured Poster
Agni 370 Practically a Master Poster Featured Poster

i thought it was 'Testnamespaces.h' .. anyways is the path of the file available in your include path? -I option of the compiler? is this file actually present in the path, did you confirm? if you're using some IDE then you might have to check what's the include path set to.

Agni 370 Practically a Master Poster Featured Poster

incode.open(" C:\\Dev-Cpp\\inventory.txt");

is that space between " and C: there in the original code also? you can remove that space and try.

Agni 370 Practically a Master Poster Featured Poster

nope.. i want to know when you get this error, in what file, whats the include statement there or anything else that you think is relevant. obviously i have no clue what you're trying to do unless you tell me..rt? ..

Agni 370 Practically a Master Poster Featured Poster

is this file present in the Test directory? can you post the include statement or the .h file if possible?

Agni 370 Practically a Master Poster Featured Poster

1> Please use 'code tags', do you see the 'Help with code Tags' on the right hand corner of your code? click that and read.
2>print_reverse definition should be preceded by scope resolution operator.
3>I don't see anywhere where you are writing the output to outstream?

please make these changes and then post the code with the 'code tags'

Agni 370 Practically a Master Poster Featured Poster

Please dont start 2 threads for the same problem. did you read the comments that were posted in the other thread? http://www.daniweb.com/forums/thread159012.html

Agni 370 Practically a Master Poster Featured Poster

you can try looking at the 'curses' library too...

Agni 370 Practically a Master Poster Featured Poster

i think it should be

int calculation(l *w);

and the other function seems alright.

Agni 370 Practically a Master Poster Featured Poster

Dont use 'eof' as an exit indicator for the loop. eof() is true only after the end of file is read and not when end of file is reached as a result your getting one extra character. use while(file.getline(<args>)) instead of 'eof'.

Agni 370 Practically a Master Poster Featured Poster

True.. i think i'll have to use row-level locks ...

Agni 370 Practically a Master Poster Featured Poster

Hi guys..

I'm facing a problem in my project. Basically its a small project for a retail store inbound section. The goods come in cartons and the user enters the carton ID in the UI to accept the carton. In the backend the carton details get updated in the table as received. Problem is that when 2 users are concurrently logged in and by mistake enter the same carton ID simultaneously none of them gets an error and the carton details are updated to twice the actual value. how do i avoid this situation?

basically i validate the carton by checking its current status in the db, which will be 'pending recv' if it has not been recvd yet. however the carton ID is being entered twice before the status gets updated. for both the guys the carton gets validated correctly and then a lot of incorrect updates happen. The architecture is client-server, multiple clients, single server.

please suggest some solution for this, i'll see if i can implement it.

Agni 370 Practically a Master Poster Featured Poster

It would be much better if you post the problem statement that you're trying to solve and also the complete code or atleast all the required and relevant code.

Agni 370 Practically a Master Poster Featured Poster

1> Destructor does the cleaning up once the object goes out of scope. it doesnt have a return type, has the same name as the class name but preceded by a '~' . like your assignment alreasy says '~Point( )', defined has

Point::~Point( )
{
     //dtor
}

just like a default ctor, if you dont declare a dtor explicitly then the compiler will do it for you. mostly you will need to declared dtors when you have dynamically allocated objects that need to be destroyed in the dtor or while using dynamic polymorphism. in the context of your assignment you need not explicitly declare a dtor.

2>There are 100's of examples right on this forum on how to do IO operations on files using stream objects. Please go through them, that would help you master the concept.

Agni 370 Practically a Master Poster Featured Poster

shouldnt you be deleting the memory allocated inside the ctor? That's a memory leak.

Agni 370 Practically a Master Poster Featured Poster

Thanks for the feedback, i'll look into those for sure.

My Consultant has suggested me the following universities as of now , could any of you please rate them in the field of computers and IT?

GLASGOW CALEDONIAN UNIVERSITY
HERIOT WATT UNIVERSITY
GREENWHICH UNIVERSITY
THAMES VALLEY UNIVERSITY
CITY UNIVERSITY LONDON

Agni 370 Practically a Master Poster Featured Poster

Please use 'Code Tags' for posting code

to your qs. you will need one more loop, something like

for(int row_A=0; row_A<num; row_A++)
{
  for(int row_B=0;row_B<=row_A;row_B++)
  {
      cout << ch;
  }
  cout << "\n";
}
Agni 370 Practically a Master Poster Featured Poster

i posted this in geeks lounge, got no response, so posting it here...

Hi Guys...

Anyone can share which are the top universities in UK for a Masters in Software Engineering and related fields? And how are they, compared to the top Univs in US and Canada?

Agni 370 Practically a Master Poster Featured Poster

Hi Guys...

Anyone can share which are the top universities in UK for a Masters in Software Engineering and related fields? And how are they, compared to the top Univs in US and Canada?

Agni 370 Practically a Master Poster Featured Poster

or you could do something like ...

int* arr = new int[rows * cols];

then go on adding elements to it ...

Agni 370 Practically a Master Poster Featured Poster

i got it, but can you explain me the difference between
float computeGross (float, float);
float computeNet (float money);
thansk

First of all you need to use code-tags always .. Nobody will even look at your code if its not easy to read, so without going through your code i'll just ans the question above..

its a simple difference, computeGross has 2 parameters passed to it, both float. computeNet has only parameter passed to it 'money' which is a float too. what is it that you dont understand in this?

Agni 370 Practically a Master Poster Featured Poster

While loop is obviously not the right choice here .. whatever grade you enter will satisfy the condition always and the loop becomes infinite... just a simple 'if' should do i think if its to happen only once. or else you can use a 'yes'-'no' sort of menu.

Agni 370 Practically a Master Poster Featured Poster

instead of an array you can use 'vector' to save unnecessary allocation of memory.

Agni 370 Practically a Master Poster Featured Poster
if(!Continue())
{
   cout << "bye" <<endl;
}

is this what you want?

Agni 370 Practically a Master Poster Featured Poster

why dont these 'for(int i = 0; ;i++)' loops have any comparison condition? when will it stop? I think before you complete this assignment you need to understand loops and arrays once more.. dont even try to solve it before you re-read those topics, ur basics are not correct and your just trying to somehow get the output without understanding what your doing here .. and you might just make yourself learn something wrong ... hit the books and then attempt it again... all the best

Agni 370 Practically a Master Poster Featured Poster

ans: i'm sure i will.. infact i just did !!!!

qs: whats a question?

Agni 370 Practically a Master Poster Featured Poster

A math grad student at Rutgers [ http://recursed.blogspot.com/2008/07/rutgers-graduate-student-finds-new.html ] has come up with a formula which can generate infinite primes

Let a(1) = 7
Define: a(n) = a(n-1) + gcd(n,a(n-1))
Then the prime generator is : a(n) - a(n-1) [one needs to ignore the 1s and then ignore the repeated primes]

Ain't that beautiful !

Agni 370 Practically a Master Poster Featured Poster

Ok so i found that out ... we need use the 'variable' and 'value' properties of the radiobutton

something like:

self.filemenu.insert_radiobutton(label=topic.strip(),index=self.indexVal,variable=self.v,value=topic.strip(),
                                             command=self.ShowTopicContent)

now when the user clicks on any menu i can check for the 'variable' value. self.v is a string

print self.v.get()

This gives me the 'value' property and i can identify which option was selected.

Keeping this still open, incase someone has a better way of doing it..

Agni 370 Practically a Master Poster Featured Poster

hi..
I havn't checked the links yet but this example is not what i want, Here we are calling a separate command for each menu option, however i have to be able to call the same command for each Menu option but in the function i should be able to find out that from which Menu Option the call has come so that i can do some specific work then. Basically for each Menu Option i will have a file of the same menu name in some locaion. So if i can make out the 'label' property in the function i can simply replace the file name with the 'label' name and thus using just one fn i can accomplish this. i need this because the menu options are extensible also, so i cant dynamically keep adding more fns for new menu's. hence i need to fire just one command for each option

Agni 370 Practically a Master Poster Featured Poster

Hi,

The same code as my previous post, but because of this list thing, i'm not able to run specific commands for different options. Here i have 2 options under the 'Names' Menu, 'rajat','prasun', now when the user selects either of them i should be able to know which one he selected and run the command associated for it. i've tried some stuff like trying to use 'variable' or 'value' properties but its just not working.. any hints would be helpful..

from Tkinter import *

fileObj = open("c:/test","w")
fileObj.write("rajat")
fileObj.write("\n")
fileObj.write("prasun")
fileObj.close()

file1 = open("c:/test","r")
lines = file1.readlines()
file1.close()

root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar)
menubar.add_cascade(label="Names",menu=filemenu)

for line in lines:
    filemenu.add_cascade(label=line)

root.config(menu=menubar)
root.mainloop()
Agni 370 Practically a Master Poster Featured Poster

simple and exact ... worked perfectly... Thanks a lot.

Agni 370 Practically a Master Poster Featured Poster

Hi,

Below is my test code, i have a list of names in a file, i read the names and i have to insert them as menu options in the menubar. Since its a dynamic menu and people can add new menu's it has to be read from a file everytime its loaded. Problem is that its appending an extra character after everyname in the menu, something line '[]'(check the attached screen shot) which i assume is the newline char, since i'm inserting that too... How can i get rid of that, any suggestions? i tried reading and writing the file in binary mode but makes no difference.

from Tkinter import *

fileObj = open("c:/test","w")
fileObj.write("rajat")
fileObj.write("\n")
fileObj.write("prasun")
fileObj.close()

file1 = open("c:/test","r")
lines = file1.readlines()
file1.close()

root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar)
menubar.add_cascade(label="Names",menu=filemenu)

for line in lines:
    filemenu.add_cascade(label=line)

root.config(menu=menubar)
root.mainloop()
Agni 370 Practically a Master Poster Featured Poster

Why dont you just compile and test it?

Agni 370 Practically a Master Poster Featured Poster

and you need a default constructor of the class too, since you have declared your own ctor the compiler will not generate it for you...

Agni 370 Practically a Master Poster Featured Poster

Its working correctly for me ..
output:

What is the number : 10
The nodes contain the numbers:
10 --> NULL
What is the number : 2
The nodes contain the numbers:
2 -->10 --> NULL
What is the number : 15
The nodes contain the numbers:
2 -->10 -->15 --> NULL
What is the number : 1
The nodes contain the numbers:
1 -->2 -->10 -->15 --> NULL
What is the number : 25
The nodes contain the numbers:
1 -->2 -->10 -->15 -->25 --> NULL

-- n i made a change to ur code

newPtr=(NodePtr)(malloc(sizeof(struct Node)));
Agni 370 Practically a Master Poster Featured Poster
Agni 370 Practically a Master Poster Featured Poster

you can find loads of examples-definitions on google.. go through them.. then when you have more specific doubts ppl here can help .. happy learning :)

Agni 370 Practically a Master Poster Featured Poster

simply use the 'c_str' function of the string class to convert to c-style string.

Agni 370 Practically a Master Poster Featured Poster
fstream openfile;
openfile("my_file.txt");
if(openfile.fail())
{
      cout<<"Error opening file.";
}
else
{
      mainprog();
}

i'm surprised that this doesn't give you a compilation error. when i compile it i get a straight forward error

fileopenDan.cpp(9) : error C2064: term does not evaluate to a function

and the both the forms work well if you say

openfile.open("my_file.txt", fstream::in|fstream::out|fstream::app);
Agni 370 Practically a Master Poster Featured Poster

Thanks a lot guys ... all these were excellent solutions... i'm trying to condition my 'approach' to solving problems ....

Agni 370 Practically a Master Poster Featured Poster

Hi Guys,

i just wrote a program to print a sentence backwards using recursion. But i'm not too happy about it, if someone can give me a more optimized solution i'll be glad. You have to use std::string class.

input:
where the streets have no name
output:
name no have streets the where

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

// read a sentence and print it backwards using recursion

std::string mySentence(std::string);

int main()
{
	std::string query;
	std::cout << "enter a sentence" << std::endl;

	if ( std::getline ( std::cin,query ) )
		std::cout << mySentence(query) << std::endl;
}

std::string
mySentence(std::string sentence)
{
	std::stringstream ss(sentence);
	std::string token;
    int wordCount = 0;
	while(ss>>token)
	{
		wordCount++;
	}

	if(wordCount == 1)
		return sentence;

                int count = 0;
	std::string::iterator it;
	it = sentence.end();
	while(*it != ' ')
	{
		it--;
		count++;
	}
    int len = sentence.length();
	int pos = len - count;
	std::string subString = sentence.substr(0,pos);
	return sentence.substr(pos) + mySentence(subString);
}
Agni 370 Practically a Master Poster Featured Poster

Then you need to create a structure and create a vector of that structure. which brings us back to the few first replies in this thread and the circle is complete....

Agni 370 Practically a Master Poster Featured Poster

what do you mean by 'read internet data' ? If it means making an HTTP 'get' request to some URL and getting the data that i think you can try using the 'curl' library http://curl.haxx.se/

Agni 370 Practically a Master Poster Featured Poster

what i have to put in the fopen?

i think you need a '/' something line "e:/reservat.txt"

This is more of a C code though and please read about 'code-tags'.

Agni 370 Practically a Master Poster Featured Poster

for pointers you access the class members using '->'

hence the line should be

int i = Human->getHealth();

see the error carefully

left of '.getHealth' must have class/struct/union

if its a class/struct/union you can use '.'

Agni 370 Practically a Master Poster Featured Poster

yah i want to open a file file1.dat write content into it ..close and oen a new file with a name file2.dat write content n close it .. and continue this !!

I assumed you needed multiple files open at the same time, for above requirement AD has already given you the code. Go through it.