Agni 370 Practically a Master Poster Featured Poster

You probably need a class called 'Player' which has a stack data member of type card. You can use the c++ stack container which provides you methods to add/remove elements. You don't really need to learn linked list to understand how this container works but you should still learn about linked list anyways since they are so basic and important to understanding a lot of datastructures.

Create as many Players as you need and go about extract cards from the deck and adding to the players decks. That should be the next step.

Also, your main should have the signature 'int main()' and get rid of system("pause"),use std::cin.get() to halt your program if you want.

Agni 370 Practically a Master Poster Featured Poster

We were infact using the 80/20 rule earlier but when we got these new products the issue list started growing pretty fast and we realised this rule will not be enough to handle this situation. It was down to 2 main reasons: 1. Our unfamiliarity with the new code base and 2. Not so great a job at testing by the earlier team. So we started trying different ways to bring the situation under control.

We're using a better prioritization process than earlier now and also have someone looking at the issue list, acting as a mediator and it's working better right now.

It does however made us realise that there are some critical testing components missing in our day to day process. Also our debugging tools are good but not that great. Which makes me want to ask what sort of tools/techniques do people use, but will probably start a new thread for that.

Thanks for the suggestions guys.

Agni 370 Practically a Master Poster Featured Poster

Can you post whatever code you have written so far ?

Agni 370 Practically a Master Poster Featured Poster

Please post the compliation errors if you want quick help.

Agni 370 Practically a Master Poster Featured Poster

Normally you would have an insert function which takes care of head node. Not sure why would you want to insert at tail directly. Also you can have insert_at or insert_after, insert_before functions which also handle adding a node to an empty list. Take a look at this tutorial here Linked List Tutorial

Edit: Forgot to mention that you don't need to check for NULL ptr after New. If it fails to allocate memory it will throw a bad_alloc exception . And also don't use exit in the middle of your code

Agni 370 Practically a Master Poster Featured Poster

Ok so I like these suggestions

Preferably you need an updated list each week, so you can work for a longer period without changes. If something really urgent comes up, you can include it, but other things will have to be postponed.

.

You might even appoint one or two people whose sole task will be for a few weeks to sift through the mass of issues and filter out those that can be safely discarded or shifted to the backlog as "nice to haves"

I guess they are some what related but instead of us guys going over all issues everyday some dedicated person to provide updated prioritized list will be better. Also it will stop us from jumping from 1 issue to another in an attempt to fix them all.

Agni 370 Practically a Master Poster Featured Poster

We have a small team of 5 software developers and we are handling products A & B. Last month we were also handed over products C & D from another team which moved to doing something else. Suddenly we have double the work and same number of people. Though we are in the process of hiring it will take some time. Right now we have a huge number of issues and urgent projects and it's getting a bit messy. It seems every week we try a new strategy to tackle the situation but it's not working out. For a week we only worked on issues so that we could get them under a reasonable number but it didn't really work as more kept coming and output was not as great as we thought for various reasons. Now we're 1 week behind on project work and not that much better off on issues.

Was just wondering if anyone here has been through such situations and could share how they tackled it ? I'm not looking for a magic wand but it could be helpful to see if someone tried an interesting approach and it worked.

Agni 370 Practically a Master Poster Featured Poster

I'm using CC
CC: Sun C++ 5.10 SunOS_sparc Patch 128228-19 2012/05/23

the technique worked brilliantly for me. The fact that I don't have to expose types which are not needed for a particular namespace makes it so much better.

Thanks again !

Agni 370 Practically a Master Poster Featured Poster

Thanks a lot mike_2000_17.I did think it was not that elegant but it worked for a first few cases and I didn't think if there was a better way. The technique you have explained definitely looks much better and i'm going to try it out and come back to you if it fits all my cases. I'm new to this sort of template programming so these techniques are not very obvious to me. Also that was a very nice explanation for the template rules and compilers. I had a feeling I was in compiler dependant territory but was not sure about it. Thanks again !

Agni 370 Practically a Master Poster Featured Poster

I have a some libraries which have a lot of common classes but the namespaces are different. Most of the code I was writing could be easily reused by classes in both libraries so after some reading I tried a technique of using the templates to pass namespace. As you can see in the program below. However the issue is that not all classes are common so I create different templates to pass to Util. (templateNamespace and templateNamespaceb)

I was expecting that if I don't pass a type and not call a function it should not get generated and things should be fine. However it only works if the the type is not in the function signature. So for eg in the code below, namespace B does not have the type 'T2' and 'print2' in Util depends on T2. If I change print2 to 'void print2(typename schemans::T2 t2)' this program does not compile saying 'B' does not have T2 but if I declare it inside the function it compiles fine. could someone please explain the behaviour ? I hope I have explained it well if not let me know and i'll try again

#include <iostream>


namespace A
{
    class T1{
        public:
            int i;
    };

    class T2{
        public:
            int x;
    };
};

namespace B
{
    class T1{
        public:
            int i;
    };
};

template <typename schemans>
class util{
    public:
        void print(typename schemans::T1 tobj)
        {
            std::cout << tobj.i << std::endl;
        }

        void print2()
        {
            typename schemans::T2 t2;
            t2.x = 13;
            std::cout << …
Agni 370 Practically a Master Poster Featured Poster

I didn't really know what 'isalnum' does so i checked the c++ reference site and it says "Check if character is alphanumeric. Checks whether c is either a decimal digit or an uppercase or lowercase letter." So that seems to be the issue ? May be you should use 'isdigit' which is in the same header.

Agni 370 Practically a Master Poster Featured Poster

Also when you declare a non-virtual function in a child class which has the same name as the base non-virtual function you end up 'hiding' the base function which might not work as you expect. The base class function is not accessible in the derived object now. Even if the function signature was different. Can read more here Hiding C++

Agni 370 Practically a Master Poster Featured Poster

Are you learning C++ ? What material are you using ? Any decent C++ book or online resource should give you a good explanation of arrays and how they are used. Try this http://www.cplusplus.com/doc/tutorial/arrays/

Agni 370 Practically a Master Poster Featured Poster

need some help again with finding the min and max from a text file

And where is your logic to calculate min and max? What do you think the algorithm should be on paper ?

Agni 370 Practically a Master Poster Featured Poster

So it looks like you have managed to read the words ending with 'ed' in the vector ? Now in 'append_to_file' you have to do a similar operation as above but instead of ifstream you need to create an object of 'ofstream' and open the file in 'ios::out' mode and write the vector into it. ios::out mode overwrites the contents of the file while ios::app mode will append to the end of the file. Pseudo-code would look something like

std::ofstream outfile("myfile",ios::out);
if file is open{
    loop for vector
        outfile << vector[index];
}
Agni 370 Practically a Master Poster Featured Poster

Why do you need an automata ? It doesn't look like you need to check for strings matching any regular expressions. Just load the contents of the documents as string and do a find for the required strings.

Agni 370 Practically a Master Poster Featured Poster

Yes. You are subtracting ascii value of char with ascii value of '0'

Agni 370 Practically a Master Poster Featured Poster

To begin we need to know what have you tried and where are you stuck. If you post whatever code you've written we can help you fix it. It's also a good way to guage how much you already know and what level of details should be included in the response.
Edit: @pyTony beats me to ..

Agni 370 Practically a Master Poster Featured Poster

There is a related article link on this page (i'm assuming you see it too) File Display Proram , Take a close look at the includes, the use of ifstream object for reading files, namespace std, cout etc.. That is the std c++ way of writing code. i'm guessing you've just started so it's best to get the basics right before we get to the logical errors.

Agni 370 Practically a Master Poster Featured Poster

Cool. Then go ahead and do it and post back if you face any issues.

Agni 370 Practically a Master Poster Featured Poster

@Salem: How does the link here 'from a stone age educational system.' help the OP and why did you think it was needed to be shared on this forum ? You didn't need to share it because every student in india knows this, there are a lot of factors behind these things but people like the OP are still trying to learn instead of crying about what kind of teachers/facilities they have or don't have.
Daniweb didn't use to be a place where we tried to show our biases. I can find a hundred articles about problems in educational systems in almost every country in this world so every time someone asks a question should I first tell them that their education system sucks ?

Celtrix commented: Exactly and most Education systems don't lack in compilers they simply lack in knowledge of the OSF and GNU projects ;P +3
Agni 370 Practically a Master Poster Featured Poster

As difficult as it is to make out much from your post above, I mentioned 2 alternatives in my earlier post, do you fancy using any of them ?

Storing the words and their meanings in a file and then loading from the file seems quite natural to me though.

Agni 370 Practically a Master Poster Featured Poster

I don't understand why you wish to store the words and their meaning without using file handling. Either you can hard-code all possible words-meanings into the program(highly improbable and bad) or you can use a database to store words and their meanings and then fetch them from the database. Which option do you prefer ?

Agni 370 Practically a Master Poster Featured Poster

Hi,

Could you elaborate clearly what is it that you want to do and what are the issues you are facing ?

Agni 370 Practically a Master Poster Featured Poster

I'm just worried how much data is being held by one particular company. And even though they say that they will not misuse the data, they do realise the kind of power it gives them in this e-society. Tracking people's transactions is going to be another such way to get even more information. With technology out-pacing the laws it is also difficult to charge these organisations in case of intentional or non-intentional misuse. Not to forget that Google has in the past caused breaches to the data-protection acts by collecting data without user consent etc.

Agni 370 Practically a Master Poster Featured Poster

Thanks Narue for the explanation and the examples were very helpful.

Agni 370 Practically a Master Poster Featured Poster

Thanks Narue, I think i've understood the concept now.

I have another question on a slightly different part from the same book. This is regarding the adjustment to the 'this' pointer. According to the book in case of a multple inheritance if we point the second base class pointer to a derived class,

class Derived: public Base1, Base2{
     
}

Base2* ptr = new Derived();

compiler requires to adjust the 'this' pointer, using something called a thunk to get to the Base2 subobject within the Derived class. The adjustment looks something like

Derived* temp = new Derived();
Base2* ptr = temp ? temp + sizeof(Base1) : 0

However it doesn't say if a similar strategy is used in case of multilevel inheritance, something like

class Base1{
}

class Base2 : public Base1{
}

class Derived : public Base2{
}

Base2* ptr = new Derived(); //will this also require a this pointer adjustment ?

tbh i'm not really clear of why multiple inheritance is more expensive than multilevel inheritance.

thelamb commented: Nice question, refreshing (Y) +3
Agni 370 Practically a Master Poster Featured Poster

Thanks Narue. I think I knew that but got confused looking at the way the virtual function call was transformed in the example, something like (*ptr->vptr[4])(ptr), and ptr is the pointer to base type pointing to a derived class object. If i'm not wrong the vtable pointed to by vptr also contains the address of the virtual functions unique to the child class? and i was wondering what stops the compiler from finding the address of a child class function which might be in the next slot in the table? How is the type of object used here to determine which functions are not a part of base class ?

Agni 370 Practically a Master Poster Featured Poster

Sure,

Lets say we have a base class, 'Base' , derived by another say 'Derived'.

class Base
{
     public:
        int _x;
        virtual void y();
        virtual void z();
        virtual ~Base();
}

class Derived : Base
{
     public:
      virtual void y();
      virtual void newfnc();
      virtual ~Derived();
}

Now, Derived class's virtual table contains the address of the virtual functions inherited/overridden from base and the address of the new virtual function 'newfnc' declared in derived.

The virtual pointer in derived points to this vtable. If I have a Base pointer pointing to the Derived object will it still not be using the same virtual pointer? If yes, then how does the compiler prevent us from calling the 'newfn' function using the base pointer, since the virtual table has the address of newfn and we have a pointer to the table.

I'm probably too confused, if it's still not clear i'll try to get the diagram in.

Agni 370 Practically a Master Poster Featured Poster

I have been reading the 'inside the c++ object model' by Lippman and one of the sections has me a little confused. It is the section where the author explains how virtual tables are created and virtual pointers assigned, in the scenario of multilevel, single inheritance. If anyone here has the book i'm referring to the diagram on page 129, figure 4.1 (I think there's only 1 edition) and the statement mentioned on the next page that if a derived class adds a new virtual function, a slot is added to the end of virtual table which contains the address of the new virtual function. Now since there's only 1 vptr in the class, how does the compiler stop it from accessing the new virtual function even if I have a base pointer pointing to a child pointer. As the vptr, if i'm not wrong is the same?

If needed I can upload an example object model.

Agni 370 Practically a Master Poster Featured Poster

Having said that, Do you guys think that allowing facebook comments for sections like 'News Stories' will make it easy for non-members to interact with daniweb writers and members ? May be some of them then become members to take a greater part.

Agni 370 Practically a Master Poster Featured Poster

Have been reading about the facebook commenting API for a few days now. Sites like Techcrunch have gone ahead and implemented the feature. I tried imagining if it will make sense for a forum like Daniweb to enable facebook commenting ? To me it seemed that it will not make much sense for Daniweb to do this as this is a forum to get answers and much different from a site like Techcrunch. Moreover anonyimity is probably something that is liked by the members here and they are remembered by their daniweb avtaars, signatures and offcourse their unique and interesting daniweb usernames. What do you guys think about the idea of enabling facebook comments on daniweb ?


[ Can the mods please move this to geeks lounge? ]

Agni 370 Practically a Master Poster Featured Poster

Looking at your printmaze function it looks very likely that you have missed some matching opening and closing braces somewhere. Just try and ensure that.

Agni 370 Practically a Master Poster Featured Poster

It looks to be this line

for(node *temp=firstNode; temp!=NULL && temp->next!=NULL; temp=temp->next)

Lets say you removed the one and only node in your list. In the code you hit the else part and do a 'delete firstNode', however you are not setting the pointer to null. Then you come to this line and assign the address in firstNode(which is still there in firstNode) to temp and then try and access temp which gives the segmentation.

You could set firstNode to null after you delete it but generally you should try and avoid situations where you use a pointer after a possible deletion.

Agni 370 Practically a Master Poster Featured Poster

On the same lines you could have a map that maps strings to function pointers. Provided you can have all functions to have the same signature (or if you can create delegate functions which have the same signature and internally call the respective functions) and then can directly call the function based on the input string.

Example:

#include <iostream>
#include <map>
#include <string>

typedef void(*pf)();
typedef std::map<std::string,pf> FnMap;

void letsWork(const std::string& work, FnMap* fnMap);
void work1(){	std::cout << "work1" << std::endl;}
void work2(){	std::cout << "work2" << std::endl;}

int main()
{
	FnMap* fnMap = new FnMap();
	
	std::string _work1 = "work1";
	std::string _work2 = "work2";

	fnMap->insert(std::pair<std::string,pf>(_work1,work1));
	fnMap->insert(std::pair<std::string,pf>(_work2,work2));

	std::string work;
	std::cout << "What work?" << std::endl;
	std::cin >> work;

	letsWork(work,fnMap);
	
	std::cin.ignore();
	std::cin.get();
	
	delete fnMap;
}

void letsWork(const std::string& work, FnMap* fnMap){
	if(fnMap->count(work) > 0) (fnMap->find(work))->second();
}
Agni 370 Practically a Master Poster Featured Poster

It seems like you want a subscriber-publisher model. There will be one publisher thread which calls a particular function on all subscribers every 60 seconds. The publisher can be a Singleton and subscribers could just subscribe with a callback function to it. However if there is only 1 publisher then it could be that a new foo object subscribes just a fraction of second before the publisher is going to wake up so the first call can be at any time after you subscribe. All other calls will happen at 60 seconds periods though.

Agni 370 Practically a Master Poster Featured Poster

Is there any way to have a pointer pointing to each line? Any way to implement it?

You could store the entire file as a vector of strings and then do whatever you want to do with them. Something like

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

int main()
{
	std::ifstream repFile("file1.txt");	
	
	std::vector<std::string> fileVector;	
	
	std::string repLine;
	while(getline(repFile,repLine))
	{
		fileVector.push_back(repLine);
	}

	for(int i=0;i<fileVector.size(); i++)
	{
		std::cout << fileVector[i] << std::endl;
	}

	std::cin.get();
}

Also if I compare one line of file 1 to all lines of file2 and if it doesnt match with any, print out that line...will that work?

That depends on what your program is expected to do. I can't possibly answer that.

Agni 370 Practically a Master Poster Featured Poster

You need to have some logic to find out which lines are the 'extra' lines and can be ignored while comparing. for example say a line starting with 'line67' is noise and should not be compared. If on the other hand it is random then I can't imagine a workaround and the comparison makes no sense.

Agni 370 Practically a Master Poster Featured Poster

Can you post the input files here ? A small portion may be ? As far as i know getline reads the entire line along with the spaces if any. Do you mean you have a few blank lines in between? This was the input I used and it worked fine

file1.txt

line0
line2
line3
line4
This is the last line

file2.txt

line0 are you there
line2
line4
line3
This isthe last line

Report.txt

line0 are you there
line4
line3
This isthe last line
Agni 370 Practically a Master Poster Featured Poster

I copied and ran your code and it worked fine for me. On unix though. Btw main should have a return type of int and you should remove all the unnecessary headers and don't use System("pause") , use cin.get if you want to pause your program.

Use couts to print out each line as you read and try using a debugger.

Agni 370 Practically a Master Poster Featured Poster

Do you have the permissions to read the file/directory ?

Agni 370 Practically a Master Poster Featured Poster

By last error I assume you mean

35 error: request for member 'name' in 'emp', which is of non-class type 'worker_t*'

emp is a pointer to the base address of the array of worker_t and not the class type itself. You cannot say emp.name hence. You have to get each element in the array and then call the appropriate function or memeber something line

emp[0].name // or emp[loop].name
Agni 370 Practically a Master Poster Featured Poster

No you cannot inherit an array because if i'm not wrong it is considered to be POD(Plain Old Data) in C++ and doesn't have ctors etc.

I don't see why a Matrix class should inherit any container. Containing an array or a vector seems like a logical solution to me.

Edit: <Too Late.. >

Agni 370 Practically a Master Poster Featured Poster

Do you mean to pass the array and then the size separate?

Yes. When you say &employee[10] you are not passing the size, you are just passing the address (employee + 10) which is infact beyond your array. You need to pass the address of the start of the array and its size to be able to loop that many times.

input(employee,size); //you can exclude the '&' when passing the base address of an array
Agni 370 Practically a Master Poster Featured Poster

On a slightly more pedantic note, Read this before posting :)

Agni 370 Practically a Master Poster Featured Poster

Welcome to Daniweb. Before anyone can help you please read this Read this before posting.

Following the tips here will make it easy for people to understand your problem, read your code, provide a better solution and will help you make the most of Daniweb.

Agni 370 Practically a Master Poster Featured Poster

And ..

1. line 22, You probably want to pass in the base address of the array.
2. For an array of size 10, index 10 will take you beyond the array into unknown territory
3. line 31, in the loop you go from 0 to 10 which is an off by one error.

Some more that you should notice as you fix these.

Agni 370 Practically a Master Poster Featured Poster

Ok let me start with you :)

Initially I used to think that you're a guy, because of your avatar at that time may be. As far as ur appearance goes you always bring up the image of my English teacher from school: very thin, tall and probably you wear contacts but have a pair of geeky glasses which you wear to scare off irritating kids and ignorant programmers. As a person you seem to be smart but strict and very helpful to people who try (that's perceived from your posts here). and a bit old school in terms of likes and dislikes. WOW.. I might be completely off ;)

I also think that Jonsca's an interesting person but his description will come later ..

jonsca commented: Really, I'm anxious to hear this one. :) You have my Featured Poster interview as a starting point, no fair +0
Agni 370 Practically a Master Poster Featured Poster

Also 'names2' and also the memory allocated in addEntry fn is not being deleted anywhere.

Agni 370 Practically a Master Poster Featured Poster

As far as I can see the heads array is empty and you have not-populated it before you access it in 'tableInsert' function. So heads is actually undefined. Moreover you have a memory leak at line 97-98 since you declare a pointer to node and try to assign it to something else.

Read about linked lists here to clear your doubts, Linked List