Agni 370 Practically a Master Poster Featured Poster

first of all the naming convention is very inappropriate. Main.cpp should not be the file containing the class info rather it should be the file which contains 'int main'. The class definitions and declarations should be placed in separate files with proper names like 'class.h' and 'class.cpp' with include guards placed in the .h file. Then you should include the .h file of whichever class you need in the main.cpp.

Going forward when your project becomes bigger, it will be much easier to maintain it if you follow these rules.

Agni 370 Practically a Master Poster Featured Poster

are you 'including' the class declarations in main.cpp ???

Agni 370 Practically a Master Poster Featured Poster

for a 2-dim char array values can be extracted like

char *a[] = {"tom","som"};
cout << a[0] << "  " << a[1] << endl;
Agni 370 Practically a Master Poster Featured Poster

for starters you can create a 'login' class, which has member variables username and passwords. When the user logs in you create an object of this class with the provided username. you can store the existing data in some flat file and load it at the time of login and compare the password for this user against the passwd as saved in the file (encrypted or not is your call), this way you can authenticate. have public member functions to access username when required, like when you printing the score etc.

Agni 370 Practically a Master Poster Featured Poster

T

while(!inFile.eof())
    {
    getline(inFile, resident[i]->name);
    getline(inFile, mySSN);
    resident[i]->SSN = atol(mySSN.c_str());
    getline(inFile, myage);
    resident[i]->age = atoi(myage.c_str());
    getline(inFile, resident[i]->address);
    getline(inFile, skip);
    i++;
    resident[i] = resident[i-1]->next;
    }
    resident[i]->next = NULL;

I try compiling and it passes again without errors, yet it is still crashing. Is there anything wrong with what I'm doing?

what are you tryint to do here

i++;
 resident[i] = resident[i-1]->next;

for i = 0 you will increment i first so i = 1 then you say
resident[1] = resident[0]->next; resident[0]->next was not set to any value and NULL so resident[1]->next is also NULL and so on and so forth. In a normal forward link list the first element has the link to the second element and so on. so while inserting you need to handle the case of the first node separately. The last node's 'next' pointer should be NULL only.

avoid using eof(), Read This.

And why do you need an array of info*'s ?? This seems like a hybrid of arrays and linked list !!!

Agni 370 Practically a Master Poster Featured Poster

Sir,

Since you are new here and this is your first post let me bring to your notice that no one here will give you a code on a platter. This is not a code writing machine here. Please try it on your own and post the code if you face any problems and then someone will help you cross the hurdles. That's how we work here!!

hope to see your code soon.

Agni 370 Practically a Master Poster Featured Poster

it is, so when you increment it you don't go to the next element but to the next 'array' !!

char *p[4] = {"yo","po","to","go"};

	for(int i=0;i<4;i++)
	{
		cout << *(p+i) << endl;

	}

output:
yo
po
to
go

p[0] = "yo"
p[1] = "po"
etc...

Agni 370 Practically a Master Poster Featured Poster

yes like that too but you can declare a 2d array as char *p[] also.

Agni 370 Practically a Master Poster Featured Poster

declaration like

char *p[10];

declares a 2-d char array which holds values like

char p[0] = "yoyo";
char p[1] = "pogo";

you can use a 1-D char array for your assignment. change the contents of the array by passing its base address(like i have done in the sample code) and then pass the same to another function and it should work.

Agni 370 Practically a Master Poster Featured Poster

To do it simply you can declare sentence1 as a simple char array rather than a 2d char array.

i modified your code to illustrate this you can put your logic back again whatever it is. i havn't compiled it so cant guarantee against that. Any reason why you were using a 2d char array?

#include <iostream>
#include <cmath>
#include <cctype>
using namespace std;

const int SIZE = 61;

void getinput(char []);
void compare(char [], char []);

int main()
{
	char sentence1[SIZE];

	getinput(sentence1);
	cout << sentence1 << endl;
	//getinput(sentence2);
	return 0;
}

void getinput(char sentence[])
{
	char sentence_temp[4] = {'a','b','c','d'};
	int k = 0;
	while (k <= 3)
	{
		sentence[k] = sentence_temp[k];
		k++;
	}
	sentence[k] = '\0';

}

void compare(char sentence1[], char sentence2[])
{


}

:) its the same point as Murtan's. I didn't refresh i guess.

Agni 370 Practically a Master Poster Featured Poster
while(ch >= ' ' || count <= SIZE)
	{
                
		if (isalpha(ch))
		{
			sentence_temp[i++] = ch;
		}
                cin.get(ch);
		count++;
	}

does this ever exit?

Agni 370 Practically a Master Poster Featured Poster

can you post the function code here?

Agni 370 Practically a Master Poster Featured Poster

where's the code for TestAccount.cpp?

Agni 370 Practically a Master Poster Featured Poster

well when you create the object of the child class the base class ctor gets called and since you have declared your own ctor the compiler doesn't give you a default ctor. In the definition of the child class ctor you should pass the required value to the base class ctor.

something like

SavingsAccount(double initBalance, double initInterestRate):Account(initBalance) {
			InterestRate = initInterestRate;
			Balance = initBalance;	
		};
Agni 370 Practically a Master Poster Featured Poster

i actually fail to understand your logic for deletion

q=p->link->link;
p->link=q->link;
q->link=NULL;

free(q);

1> why are you checking for p->link->NUM and not p->NUM directly?

2> when you find it, you assign q to p->link->link and then free(q), shouldn't you be freeing p->link instead?

Agni 370 Practically a Master Poster Featured Poster

Why do you need to write and call separate c++ programs for each of these functions to execute? Is there a special requirement to do this? Was writing different function not allowed? if you still have to do it i think you can do this by using the 'system' command and giving the program name without any extension. I still fail to understand the requirement though and would like to attach a 'Do at your own risk' tag to it :)

Just out of curiosity, you do know that if you call a function from 'MAIN', main will not terminate till the control returns back from the function, right?

Agni 370 Practically a Master Poster Featured Poster

what is 'START' program? is it a shell script or is it a .exe file? Are you on windows or *NIX?

Agni 370 Practically a Master Poster Featured Poster

1> you dont need to create separate threads for same problem. you could have 'edit'ed your earlier post instead or if it was replied to you could have again 'replied' with your query.
2>system should execute any executable, it need not have a .exe extension, as per my understanding if you're on *NIX you can give the name of any file which has execute permission.

Agni 370 Practically a Master Poster Featured Poster

Try

system("sh test");
system("test.exe");

i think you will need the header 'process.h' for this.

Agni 370 Practically a Master Poster Featured Poster

- Learn to program (stuff which is relevant to all programming - eg. design)

Strangely though they teach us to code a lot more before they even touch the design patterns. I find it very difficult to grasp design patterns due to sheer lack of direct application. The product i work on was build long before i joined the company. its stable and the base framework is sturdy, whatever we code is within the framework and hence hardly any chances of trying new design patterns :(

Agni 370 Practically a Master Poster Featured Poster

1> i dont know if this will work(i mean the vector thing, not struct way). but assuming it does,
one issue i see with using a vector is if you have to verify that a particular point is on the right path or not. Suppose you have a maze and someone is trying to go through it and you need to verify that he's on the right path how do you do that? do you fetch each element which is an array and then compare each element of that array with the present co-ordinates? That would be pretty slow.
3> May be we can create a string of x-y coordinates.
row = 2, col =3
create a string "0203" and store strings in vectors, comparison might also be easier.
4> All these are as per my understanding of the problem ;)

Agni 370 Practically a Master Poster Featured Poster

my 2 cents:
-> you can declare pointers and references to the abstract class to use polymorphic behaviour

Agni 370 Practically a Master Poster Featured Poster

did anyone notice.. this thread has been viewed '2,484' times .. strange :) ...

ok i checked most such old threads have been viewed a lot of times .. seems not so strange now ...

Agni 370 Practically a Master Poster Featured Poster

Wish Everyone on Dani a great 2009 :) ... Lets all of us learn more and share more and make this new year a great One !!!!... had a wonderful time on daniweb till now, hope to have many such years...

Good Luck...

Agni 370 Practically a Master Poster Featured Poster

Header required for 'TButton' is missing i think.

Agni 370 Practically a Master Poster Featured Poster

Hi Guys,

I'm trying to create my own DBMS. For now i want to create a simple one where i can 'create' tables, 'insert' data and do a 'select' for all values(no where condition as of now). Very basic features. This is the first design/pseudo code that i have come up with. I'll be using a .dat file to save data, one file for each table. It will have a 'headerInfo' at the top indicating the columnNames|length (i'm not checking dataType as of now. I'm thinking of using sql style query system which i will parse and confirm syntax, No UI as of now.

Please see this pseudo code and let me know what are the drawbacks/incorrect design or any possible road blocks i'll encounter if i try to extend this.

Class Object
function: create
function: loadObjectDictionary
function: updateObjectInfoFile
----------------------------------------
m_objectDictionary tableName-FileName
Class table:Object
function: create
create a new file for the table
create a 'table_header_info' which is delimited string of columns|length
open file
insert header info at top of file.
close file
insert the table_name-fileName entry in 'm_objectDictionary'
function: insert
load m_headerInfoDictionary
validate number of values and size of each column against length
if validations are fine
open the file.
add row
close file
else
error
function: select
create object of 'table' class using tablename
load the corresponding file using tablename from m_objectDictionary

Agni 370 Practically a Master Poster Featured Poster

my current favorite:

#include <pthread.h>
Agni 370 Practically a Master Poster Featured Poster

what kind of functions does that API provide you? createNode, deleteNode etc.? can you post the function signatures here? Are there any functions which return pointer to a node?

Agni 370 Practically a Master Poster Featured Poster

Friend function can access private data. Period. Please don't learn wrong things.
For your original problem if you post the code you compiled we should be able to help you understand the real issue.

Agni 370 Practically a Master Poster Featured Poster

1> Please use codeTags to make it easier for everyone to read your code.

2> i dont see a problem here. Is there some more code? Where do you initialize the variables? Post the full code.

3>

But my best guess is the friend function doesn't have access to the private class members

Whats the point of guessing? You either give the right answer or refrain from posting.

Agni 370 Practically a Master Poster Featured Poster

It doesn't matter than 'i' doesn't exist when main() ends and the thread is using it, simply because when main() ends the whole program shuts down, including the threads.

The threads wont shut down because I'm using 'ExitThread', if I'm not wrong its the equivalent of pthread_exit for Unix.

Agni 370 Practically a Master Poster Featured Poster

>>ExitThread(0);
delete that line in main()

But if i do that the threads never execute as 'main' terminates and all the threads die. Any reason why you think it might help?

I found a possible solution to the problem, since the threads would sleep in 'Display' and by the time they wake up, main exits hence 'i' doesn't exist anymore and when i try to print the value it crashes. Actually i executed it once without the 'sleep' and it went through fine. Though i think it might still crash some other time when main exits before any of the threads is left incomplete.

Agni 370 Practically a Master Poster Featured Poster

This code here is giving segmentation fault. Any clues why? also any general tips for writing good multi-threaded code are welcome.

#include <windows.h>
#include <process.h>
#include <iostream>

using namespace std;

unsigned __stdcall Display(void* p)
{
	Sleep(500);
	cout << "Display" << endl;
	cout << *((int*)p) << endl;
	return 0;
}
int main()
{
	unsigned taddr = NULL;
	unsigned createFlag = 0;

	for(int i=0;i<5;i++)
	{
		if (_beginthreadex(NULL,0,Display,&i,createFlag,&taddr))
		{
			cout << "success" << endl;
		}
		else
			cout << "failed" << endl;
	}

	cout << "main's execution is over" << endl;
	ExitThread(0);
}
Agni 370 Practically a Master Poster Featured Poster

It could happen if 'vertexArray' pointer is containing some junk. When you declared it you should assign it to NULL explicitly.

float* vertexArray = NULL;
Agni 370 Practically a Master Poster Featured Poster

Can you rephrase your question? i can understand it in parts but its not very clear what you have and what you want to do.

Agni 370 Practically a Master Poster Featured Poster

Lets see, you have a structure Employeelink which has a data member 'Applicant item;' . Just like all the other members of this struct, you need to assign a value to this one also. Because its of type 'Applicant' you have to assign to it an instance of 'Applicant', which you are creating in the while loop. so every time you create a new(local) instance, set the proper values on the object and then pass it to the function where you populate 'item' with this instance.

Infact, you don't need to do that either, you can declare this instance inside the 'linkup' function itself and assign it to 'item' that ways you save the unnecessary pass-by-value part.

Agni 370 Practically a Master Poster Featured Poster

like i pointed out in the thread below this, where are you assigning anything to 'Applicant item;', ok so you changed it from a pointer to an object but where are the values? the 'app' object you create in main, should be created inside the while loop, then passed by value and assigned to another->item.

Agni 370 Practically a Master Poster Featured Poster
point->item->return_value();

should give a segementation fault.

i saw you 'Promosion::linkup' function and nowhere you are assigning anything to the 'Applicant *item;'. it will be NULL or may be garbage when you access it.


2>system("pause"); is not a good way to do this, you can find a lot of threads here that tell you in detail why. use cin.get() instead.

2>divide applicant.cpp into applicant.h and applicant.cpp and include "applicant.h" and link applicant.cpp

Agni 370 Practically a Master Poster Featured Poster

where are you struck?

I hope it didnt hurt much :) ...

Agni 370 Practically a Master Poster Featured Poster

and the errors are?? .....

Agni 370 Practically a Master Poster Featured Poster
for(i = 0 ; *Src!='\0' ; Src++)
    tmp[i]=*Src;

should increment 'i' also. as of now 'i' remains 0 throughout.

Ancient Dragon commented: Good catch :) +36
Agni 370 Practically a Master Poster Featured Poster

OK.. my bad... True .. it will not work.

Agni 370 Practically a Master Poster Featured Poster

>>I did was to Initialize char * string1 = "longer than string2" and evrything else the same and it didnt work either
I didn't work because you can't change string literals, which is what you attempted to do. But you could have done it like this: char string1[] = "longer than string2" , which will put the text in writeable memory.

I thought you could always assign a char* to another char*. Are you sure that declaring

char* string1 = "Bigger than String2";

wont work?

Agni 370 Practically a Master Poster Featured Poster

what's the type of 'IClassFact' , if its another class is the header file included? compiler is not able to deduce the type.

Agni 370 Practically a Master Poster Featured Poster

comment out

virtual void mission();

and try

and give different names for base class and derived class 'name' variable to see the difference.

Agni 370 Practically a Master Poster Featured Poster

Please see my comments in the code.

//Structure definition Person.
//contains definitions for Functionality.
#include <iostream>
#include <cstring>
#include <string>
using namespace std;


struct PERSON
{	
	char firstName[20];
	char lastName[20];
	char address[50];
		
};
const int MAXPEOPLE = 2;
PERSON people[MAXPEOPLE];
PERSON p; // you dont need this global variable
//.cpp file
//Contains functionality of addressBook

#include <iostream>
using namespace std;
#include "definitionsAddressBook.h"

int addPerson(PERSON p);
int getPerson(PERSON p);


int addPerson(PERSON p)
{ 
	for(int i = 0; i < MAXPEOPLE; i++)
	{
                /* this is a variable local to this loop. every time this function gets called a new array is created and you then add the element to the 0th location of this array. Do you need this or the global array declared in .h? */	

		PERSON people[MAXPEOPLE]; 	
		people[0] = p;

	}
	
	return 0;
	
}
int getPerson(PERSON p)
{
/* are you using 'p'( function argument) anywhere? if no then why add it to the function signature? */

	for(int i = 0; i < MAXPEOPLE; i++)
	{
		people[i];                
	}

	return 0;
}

int main()
{ 
	cout << "This is an address book that can hold ten people. " << endl;
	
	for(int i = 0; i < MAXPEOPLE; i++)
	{
       /* you can declare a variable of type person here and use that, everytime a new struct will be created which will passed by value to the addPerson function. */

	cout << "Please enter the first name: " << endl;
	cin >> p.firstName;
	cout << "Please enter the last …
Agni 370 Practically a Master Poster Featured Poster

How do you know its not opening the file? is it printing 'File not found' ?? Why dont you try and read something from the file and confirm?

Agni 370 Practically a Master Poster Featured Poster

Why are we not collecting the inputs into some 'double' variables directly? why so many string operations?

Agni 370 Practically a Master Poster Featured Poster

if its printing 'Hello.' then it has executed the switch statement..

Agni 370 Practically a Master Poster Featured Poster

I don't see a problem at all. The only reason could be (assuming that the file is very much present in the same directory where you are executing this code) is that you might entering 'h' instead of 'H'. Are you not getting the 'Hello.' on the screen either?