csurfer 422 Posting Pro

Its a very good thing that you are trying. There are many mistakes in your program.

1. Index of arrays always start from 0 and not 1.
2. I believe you intend to read the entire file into your array so that you can operate on it. But your reading part itself is wrong. (Try to print what you have read and you will realize). You can read the file into the array this way :

ifstream myfile;
myfile.open("blob.txt");
for(int row=0;row<MAXROW;row++)
{
    myfile >> ba[row];
}
myfile.close();

4. For get blob and destroy blob put your thoughts as to what you want the function to do on a paper and then try to code the functions.

Happy Coding :)

csurfer 422 Posting Pro

Its just one of the ways used within the working of a computer to make the best use of available space.
Say your program after compilation is converted into set of instructions like

Address Instruction
00000000 <Start>
00000001 <Instruction 1>
00000002 <Instruction 2>
00000003 <Instruction 3>
...
00000300 <End>

Here you can assume the program to be of 300 byte length and each instruction occupying 1 byte space. So the address you see beside an instruction is its logical address. Logical address has significance within the program. It can be viewed as an offset within a file.
Now this program has to be loaded on to the execution space within computer and there it would start from some address say ABCDEFAB , this is called the base address and adding the logical address of an instruction to this base address we get the actual "Physical address" of the instruction which is used by the CPU to execute that instruction.
This whole structure is relocatable as just by changing the base address physical address of the instruction changes.
This is the simplest way i could explain the above question and for more detailed knowledge you can build on this idea :)

csurfer 422 Posting Pro

1. Redundant

ifstream myfile(<filename>);
myfile.open(<filename>);

2. Use \[CODE\] \[/CODE\] tags for better visibility of code.

3. Give an example of the contents so that we get a better idea.

csurfer 422 Posting Pro

I see several problems in your code.
1. void main() ??? a very bad coding practice and if your compiler is allowing this then its high time you switch to a good compiler like g++. Good practice (now a rule) is int main().
2. Why static functions for black jack class if you are calling it using an object ? "Static" is mainly used when you want to access a variable or a function without actually creating the object of that class. So try Blackjack::function() this way. By the way your present way of calling the functions also calls the functions.

csurfer 422 Posting Pro

You might be using a pre-written javascript jquery combination to do that downloaded from net. Check the javascript part for a mentioning of number like 3000 or 5000 . These are delays in milliseconds before slide transition. Change that accordingly.

csurfer 422 Posting Pro

If possible get a good book like K and R and start your programming in C. Its always better to struggle at first as it lays the foundation strong.

csurfer 422 Posting Pro

What you are doing should not be done. It may even cause runtime exceptions in some cases.Know this always "A base class pointer can be used(by typecasting) to point to a base class object or a derived class object but the reverse should never be done."

The reasoning for above is that using a derived class pointer you may try to access the functions you have added(extra) to the derived class after inheriting from the base class. This is a strict violation if the object you are pointing to is a base class object.

Try this instead :
Firstly remove the virtual tag in shape.

Circle *c = new Circle();
c->fun();
Shape *s = (Shape *)c;
s->fun();

You will get the result you are expecting.

csurfer 422 Posting Pro

I may be wrong but as far as I see you are using a single port to receive client requests from , but later when you intend to handle different clients in different threads you have to bind them to a different port for the connection to remain intact and communication to take place. If all threads are linked to the same port and you close that port all the connections are bound to get disconnected.
As its been some time that I have programmed in this field I may have gone wrong somewhere. Do correct me in case I am wrong.

csurfer 422 Posting Pro

I believe that to know how to program in any language you just need a few days but to get a hold on it it takes a life time. The only difference in Java/C# and C++ that I find is in C++ you got to do many things on your own which Java and C# have inbuilt functions for,but in C++ you can play around with pointers and also screw up the entire project due to their misuse both of which are fun :) Don't think much just go for it and enjoy the essence of programming. :)

csurfer 422 Posting Pro

Close the thread once you are done so that people can look into threads which need attention.

csurfer 422 Posting Pro

First thing you need to know is that array a in your code is an array of addresses and not values.

1. Its just your luck that this code is even running as in the last iteration of for loop when it does

a[6] += 1;

it will be pointing to a[7] which you haven't allocated and hence is a segmentation fault in most descent compilers.
2. Talking about your expectation of value "4" it should never come as you aren't adding values when you do a += 1; but incrementing the address.

What you want is a[i+1] rather than a+=1 and as stated in point 1 this will crash on the last iteration of for loop which you need to handle. Happy coding :)

csurfer 422 Posting Pro

1. Don't exactly know how name_t in your code is defined but I don't really see the purpose of using *& before charArray. I bet you are confused with passing array as a function parameter. Have a look into it.
2. If your charArray is really and array of strings rather than array of characters then you cannot compare two strings with < , you actually need to use strcmp function or your own comparison function.
3. You can reduce time by taking the pivot initially as first element and not calling find pivot function. As with a slightly different implementation the return value of the pivot would be properly adjusted at the end.
4. Have a look at this once properly.

csurfer 422 Posting Pro

How honest of you to ask for the code directly... :) Honestly people on this forum (including and especially me) are machines who cannot work without a Honest effort from your side, so come back when you have done that !!!

csurfer 422 Posting Pro

It entirely depends on the questions as to how much is the Web programmer involved. Normally a designer should provide the styling docs such as CSS , other window designs that he has come up with and documents regarding how things are related to each other. But ya the view varies from person to person and also situation to situation.

csurfer 422 Posting Pro

Try using cin.getline() along with gcount() together where in getline() can fetch you the string and gcount can help you stop according to a particular condition. Use it with caution as getline sets some error flags when encountered with a premature end of input.

csurfer 422 Posting Pro

That depends on how you want to write it within the file. If you write it the same way it appears then may be you can use getline() function to get an entire line and then process it by using the space as delimiters to get your values. Or you can add a special delimiter like '|' between terms to keep them separate and then process it the same way as mentioned above.

csurfer 422 Posting Pro

Close the thread if you are done with the question.

csurfer 422 Posting Pro

@Karan : We are not here to do someone's homework. Put in your effort first...

csurfer 422 Posting Pro

If its the Qt IDE which you are talking about , then the best way to learn using any IDE is to try out new things in it and surfing through the icons. Moreover you always will have a helper documentation for the IDE under help tab. Use that.

csurfer 422 Posting Pro

The error message itself says where you went wrong.Initialization of factorPtr in line 14 should be factorPtr(ptr) rather than *factorPtr(&ptr).

csurfer 422 Posting Pro

Take the first step and code what ever you can in what ever way you can... we will help you code but you are the one who should code.

csurfer 422 Posting Pro

If you are playing a game already built it would have been designed in a way to play against you in "Single User" mode. If you are designing the game yourself then you can write the code to make it play against you. :) So its your choice now.

csurfer 422 Posting Pro

No we cannot help you with your codes but we will help you out with the problems you may encounter while writing your codes. First know the format of image you are trying to manipulate. BMP or JPEG of 8 bit RGB or 24 bit RGB and also the construction of a jpeg file and other stuff needed from here. Once you know all these you will have a better picture of the problem in hand. Also look at convert command in Linux.

csurfer 422 Posting Pro

Anything else needed...??? Or do you want us to deliver it to the person concerned also...?

csurfer 422 Posting Pro

Ok I'm stuck again :(

Basically I want to display the question. Then display choice 1 and choice 2. I then want the program to pause, grab the users input and then compare to the answer. If the answer and the user input are the same then i want the user to gain one point. If not then i want the user's score to remain the same. I've tried this already but when i try and compare i get various errors. :S Please could someone point me in the correct direction. Thanks.

Here's the code:

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

using namespace std;

void disp_ques(char* file);


int main () {
 
 char file[100] = "example.txt";
 
 ifstream myfile(file);
 if(myfile.is_open())
 {
                     disp_ques(file); 
                     myfile.close();        
 } else cout << "an error has occured"; 
 
 
 system("PAUSE");
 return 0;   
}


void disp_ques(char* file)
{
     string line;
    
     ifstream myfile(file);
     getline(myfile, line);
     while(!myfile.eof()){
                         // What do i need to add here to Display the questions 
                         // and stop before the answer is displayed.
                         // Also need to grab users input so it can be compared to answer

                          
     }    
}

Refer to my previous post I have answered this question of yours there itself. Replace the last comment with a cin to pause and get input from the user and once the input is got match it with the answer and then display it to the user. :)

csurfer 422 Posting Pro

Assuming that your code works fine till this line(if not hoping that you will successfully solve the problems :) )you can do this :

if ((line.find(search, 0)) != string::npos)
{
      cout << "found " << search<< endl;                                               
      //Here at this point you know that the next three lines are the question and the options so you can do something as
      getline(myFile,line);
      cout<<line;
      getline(myFile,line);
      cout<<line;
      getline(myFile,line);
      cout<<line;
      //By this time you have shown the user the question and also the options so fetch his input do a getline again and compare users answers with the answer provided in the text file as the next getline returns the fourth line of the question.

}
csurfer 422 Posting Pro

By looking at your post all that I can say is as the writer of the code you are at your will to limit the input to any way by putting checks where ever necessary.And your problems :

>>Problem 1: if the input has more than 8 chars, garbage characters gets printed
let your variable be a char array of n if you want to limit it to n

>>Problem 2: if input contains invalid values(like negative), error gets printed
You can do something like

int input;
cin >> inp;
while(inp<0)
{
     cout<<"Please Enter a positive value :"<<endl;
     cin>>inp;
}

>>Problem 3: if input contains characters,( like abc), error occurs.
Check for those characters and ask the user to input proper values.Or you can intimate the user before hand that he should feed in only some particular characters and then deploy your check also.

csurfer 422 Posting Pro

You want the address of the variables list1 and maxVar to go so your summarr function call be like

result = sumarr(arr, num, maxVarHolder);
csurfer 422 Posting Pro

You can refer to this.

csurfer 422 Posting Pro

An abstract method (I assume this is what you mean by abstraction function) is a method that has no definition - there is a signature, but no provided implementation.

For example, if I have a file 'example.h'

class Example
{
public:
	int foo(int x, int y);
	int bar(int x, int y);
};

And a file, 'example.cpp'

#include "example.h"

int Example::foo(int x, int y)
{
	return x+y;
}

foo() is not an abstract method, because it has an implementation in addition to its signature. bar() is an abstract method, because it has a signature but no implementation.
Because it contains abstract methods, we cannot create an instance of an Example object.

A virtual function is something different.
A virtual function is declared with the virtual keyword. It means that if we are storing an object through a pointer to a class that is higher than it in its inheritance hierarchy, the call will still resolve to the actual method provided by the derived class.

As an example, given two classes:

class BaseClass
{
public:
	virtual int foo();
	int bar();
};

class DerivedClass : public BaseClass
{
public:
	int foo();
}

The following code snippet will behave as described in the comments:

BaseClass* ptr = new DerivedClass();	// Create an object of type DerivedClass, and store a reference to it using a BaseClass pointer
ptr->foo();	// Because foo() has been declared as virtual in BaseClass, the compiler will 'know' that we want to call the foo() method defined in the actual object - …
csurfer 422 Posting Pro

Word of advice :
1) Don't post such huge codes,just tag the file as an attachment and post your question.
2) For solving any problem try to break it into parts and solve some smaller test case. As far as i can see your Test Case 1 itself can be broken down into smaller test cases. Solve them first so that you get to know all the minute problems.Then you can deal with entire test cases.
3) Try to keep your question concentrated on a smaller part of the code so that we can analyze and help you out with your problem faster.

csurfer 422 Posting Pro

Problems :
1)The result in your sum function and the result in your main function are different as you are not at all passing the variable result to the sum function.So pass result variable also along with n to the sum function as

sum(n,result); // Make sure result is set to 0 before you make this call and change the prototype of function sum accordingly

2)Doing something like

for(int i(0),result,n;i<=n;i++)

tries to declare variables result and n again which is actually not required.Only this

for(int i(1);i<=n;i++)

suffices.

csurfer 422 Posting Pro

You have interchanged rows and cols in for loops of your print_array function,and its an obvious core dump. Change that and your code (with the changes I have made in my previous post) works.

P.S : Try to solve such simple problems by looking at your code more cautiously. Its your code, your brain child you should atleast spend some time knowing it :)

csurfer 422 Posting Pro

Ok after answering two of your questions I realize that you are just creating one thread for everyone of your questions and just delegating the work of finding the answers to these questions.
Go look into some books,google the key words out,try to implement them and then if you get some doubts then, come back to us.

csurfer 422 Posting Pro

A function which we think may be overloaded in the derived classes is marked with keyword virtual so as to inform the compiler that this function has a fair chance of getting overloaded in the derived classes.
A base class which has at least one pure virtual function cannot be instantiated and hence acts like an Abstract class in Java.

csurfer 422 Posting Pro

Inline is just a request to the compiler to treat the call to a function like a macro and substitute it rather than treating it as a function and making a call. This request may or may not be considered by a compiler where in the second case it treats it as a normal function rather than inline. So even though you do try to make a recursive function inline the compiler will ignore it and consider it as a normal function and work in the normal fashion to execute it.
P.S Doing this is definitely not a good coding practice.

csurfer 422 Posting Pro

I just made some small change in your class definition removing the .resize() and fill() functions as I didn't find their need.

template <typename T>
class dyn_arr{
public:
        //Dedault constructor
        dyn_arr() {};
		//Constructor
        dyn_arr( int rows, int cols)
        {
            for(int i=0; i<rows; i++)           
			{
				vector<T> row; // Your mistake was hardcoding int here as vector<int> as it will need vector<string> here
				for(int j=0; j<cols; j++)
				{
					row.push_back("hello");
				}
				arr.push_back(row);
			}
        }

        void print_array(int rows, int cols)
        {
			for(int i=0; i<rows; i++)
			{
				for(int j=0; j<cols; j++)
					cout << arr[i][j] << "\t";
				cout << endl;
			}
        }

private:
        vector<vector<T>> arr;
};

And ya if you are using it as a string array (dynamic) dont forget to include <string> header file.And it works. :)

Fbody commented: Here's a vote back. Good Catch. +4
csurfer 422 Posting Pro

There are several errors like :
void displayPayrollSummaryResults() returning a int value
undefined unionCode[ID] in displayEmployeeResult() and others. Please compile it and try to debug these first.

csurfer 422 Posting Pro

Refer to the algorithms I have stated in my first post. And try to implement it as far as you can. Don't worry you will get all the help you need here if you are showing some effort.:)

csurfer 422 Posting Pro

I don't see sort or next_permutation functions neither do i see the use of line 7 and the way array is defined in line 23.

csurfer 422 Posting Pro

Try netstat command followed by usage of some filter like grep.

csurfer 422 Posting Pro

Try to set a wired connection first using the options and also configure your ethernet drivers using pppoeconf in sudo mode.May be then you can try for establishing a wireless connection.

csurfer 422 Posting Pro

May be you can have a look at this once.

csurfer 422 Posting Pro

@mjoshi : Null character is represented as '\0' and not '/0' as you have done in your program.

And hope you have used double variables for sum, x etc as atof returns double.

csurfer 422 Posting Pro

Really sorry to answer to a two year old thread. I didnt look at the date just answered the thread which appeared at the top. :(

csurfer 422 Posting Pro

Solution is quite simple.Don't insert it from the end insert it from the beginning.

Assume the below given is your list :
N1->N2->N3->N4->N5->NULL

Say you have a pointer called head which does nothing but points to the starting node of the list then your list looks like :
head->N1->N2->N3->N4->N5->NULL

The point to look at is that both head and N1 point to the same memory location.So now you want to add a new node N6 then you can do something like

N6->nextptr = head;
head = N6;

So now your list looks like :
head->N6->N1->N2->N3->N4->N5->NULL

So you can go on and on inserting node (At the beginning) by using a head pointer.I think you can work your way out now.. :)

csurfer 422 Posting Pro

Have you tried to look at the patterns in printf like "%4d" "%-4d" "%04d" etc follwed by an integer value in printf ? These patterns are used to generate specific formatting of left allignment,right allignment,fixing the width of the input and also filling the empty spaces with the values you want. These are given in detail in K & R. Try them I am sure you can figure out the rest yourself as you don't exactly need anything other than this basic information to solve your present problem. :)

csurfer 422 Posting Pro

You might appreciate a full answer but we don't appreciate the idea of giving code here in this forum. So write your own program to implement the Jhonson Trotter algorithm or Heap permute algorithm using binary heaps given in A. Levitin, Introduction to The Design & Analysis of Algorithms, Addison Wesley, 2003.

sameershah21 commented: Nice attitude and great guidance +0
csurfer 422 Posting Pro

With -b option you can include a batch of commands in non interactive mode of sftp transfer . So may be you can use a c++ program with system command or exec commands to execute the commands you wanted to feed into the batch file and just pass on the output of those commands to the sftp command through pipe.

csurfer 422 Posting Pro

Check out the implementations of map and multimap if you want to know about the implementation of hash tables.

But in my view instead of creating a separate hash table why not use the functionality of priority_queue itself which has the largest element always at top? Try to collect the elements of the priority_queue in decreasing order may be in an array over which you can use a binary search.