Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is a tutorial that actually compiles, links and works. It's possible that book you are reading is just too old.

ShadowScripter commented: Already tried it, but at least you were willing to help out, maybe in time I'll see what stupid mistake I did. Thanks! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you reading a tutorial ? I don't see DirectDrawCreate being called in any of the sample programs.

I searched all the samples and found it used in two projects: Configuration System and VideoMemory. And in those projects DirectDrawCreateEx is being called as a function pointer. Like this:

IDirectDraw7* DDobject;
    HINSTANCE ddrawLib = LoadLibraryW( L"ddraw.dll" );
    if( ddrawLib )
    {
        HRESULT (WINAPI* _DirectDrawCreateEx)( GUID* lpGUID, void** lplpDD, REFIID iid, IUnknown* pUnkOuter ) = (HRESULT (WINAPI*)( GUID* lpGUID, void** lplpDD, REFIID iid, IUnknown* pUnkOuter ))GetProcAddress( ddrawLib, "DirectDrawCreateEx" ); 
        if( _DirectDrawCreateEx )
        {
            HRESULT (WINAPI* _DirectDrawEnumerateEx)( LPDDENUMCALLBACKEXA, LPVOID, DWORD ) = (HRESULT (WINAPI*)( LPDDENUMCALLBACKEXA, LPVOID, DWORD )) GetProcAddress( ddrawLib, "DirectDrawEnumerateExA" );
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I get these two compiler warnings that you need to fix before attempting to run the program

1>c:\dvlp\test1\test1\test1.cpp(36) : warning C4700: uninitialized local variable 'new_tol' used
1>c:\dvlp\test1\test1\test1.cpp(53) : warning C4700: uninitialized local variable 'ch' used

Always treat warnings are errors because in most cases they are.


>> }while (ch==0);
change that to ch!=0

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you found the samples, open one of them and browse the project linker settings, comparing them with your original program.

Also go to Tools --> Options and make sure the directories are something like the attached thumbnails

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The sample programs should be in the same directory where you installed the SDK. On my computer they are here:
c:\Program Files\Microsoft DirectX SDK (August 2008)\Samples

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i should use sql file as database format
That means nothing because there are thousands of sql file formats.

>>please help me to do this
I already have told you how I would approach the problem. But since I have not been in your class lectures I can't be sure if I was right or wrong.

The first thing I would do is write a program that reads the schema file and builds the linked list I already mentioned.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The requirement for CREATE TABLE indicates that the table contents should be read from a text file (aka schema), not hard-coded in your program.

One common way to do that is to create a structure that contains the information for each field in the table

struct field
{
    std::string field_name;
    int length; // only for strings
    int dataType; // either 1 = string, or 2 = numeric
    bool PrimaryKey; // true = this is a primary key field
};

Now when the program reads the schema file it should build a linked list or c++ vector of the above structures for each field.

What is ambiguous to me is: does your instructor expect you to actually create a table in a real SQL database such as MS-Access ? Or are you to just use a text file of your own design for it?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you mean "will you write it for me", the answer is no. If that's not what you mean then please explain in more detail why you can not write the assignment.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

that loop is backwards

while( getline( fin, s) )
{
    found=str.find_first_of(".,?;!");
   // That might find a sentence, but does not mean its the entire
   // sentence -- part of the sentence may have been on the previous
   // line -- like this comment.
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to add additional libraries as shown in the thumbnail. Of course you would have found that too had you bothered to compile one of the sample programs that comes with DirectX SDK.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i'm gettin a compile time error : Lvalue required.
which line?

>>*ptr_1=ptr1;
Probably cause an immediate crash. Why? Where does ptr_1 point to? It's undefined because it was never set to point anywhere. You can't just use a double star pointer like you are trying to do -- they don't work like that.

Here is a simple example

int main()
{
    int x;
    int* p = &x;
    int**p1 = &p;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>int memcmp_test(const char *cs, const char *ct, size_t n)
I think the first two parameters should be const unsigned char because memcmp() can work with binary blocks of data and typcasting unsigned char to char might produce undefined behavior.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Which edition of 2008 are you using (Express, Pro, etc) ? I have the Express version, downloaded the SDK Aug 2008, set up the directory paths, compiled and linked a sample program, and all went without a problem.

Before trying to write your own problem compile one of the samples to make sure your compiler's directories are set up correctly.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to post that code. Make sure the loop does not increment past the number of floats that were read, not Max_Size. The value of i in the loop I posted is the number of floats read.

for(int j = 0; j < i; j++)
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use references

class MyClass {
public:
  typedef vector<int> Vector;
  MyClass();
  ~MyClass() {;}
  Vector&  getVector() { return m_vector; }; 
private:
  Vector m_vector;
};

MyClass::MyClass() {
  m_vector.push_back(1);
  m_vector.push_back(2);
  m_vector.push_back(3);
  m_vector.push_back(4);
}

int main() {
  MyClass t;

  // This works...
  MyClass::Vector& myVector = t.getVector();  
  for(MyClass::Vector::iterator itr = myVector.begin(); itr != myVector.end(); ++itr) {
    cout << (*itr) << " ";
  }
  cout << endl;

  // This doesn't
  for(MyClass::Vector::iterator itr = t.getVector().begin(); itr != t.getVector().end(); ++itr) {
    cout << (*itr) << " ";
  }
  cout << endl;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's broken now pretty good -- now the box is shrunk too much. The attached bitmap is what it looks like after clicking the Toggle link.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

So what is the problem with that code, other than the obvious syntax error of missing closing }

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That for loop is incorrect. What you want is to read until either Max_Size has been read or until end-of-file

int i = 0;
while(i < Max_Size && inFile>>array[i] )
   ++i;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To increment (*ptr)++; Compile and run this little test program and you will see what it does.

#include <stdio.h>

void foo(int* n)
{
    (*n)++;
}

int main()
{
    int n = 0;
    int i;
    for(i = 0; i < 5; i++)
    {
        foo(&n);
        printf("%d\n", n);
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh nevermind. Probably my browser because that test link works now. :-O

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

usine FF on Vista, code inside code tags without line numbers turn is not visible when I click the Toggle link. Works ok with [code=cplusplus]. The problem only happens on random posts.

Here is an example I extracted from another post (PM) When I edit the code tags to add =cplusplus the Toggle works as expected. But without the line numbers the Toggle makes all the text disappear.

I've tried the same thing on other posts and the problem doesn't happen. So possibly there is something in the C++ code that is causing the problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It's urgent for me pls sir

But it's not urgent for any of us. I could care less whether you pass or fail -- its your grade not mine. And we are not all men, so "sir" is inappropriate.

Post what you have tried, or have you even tried to write it yourself?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just use long long or __int64 data types. One of those are supported by most, if not all, modern compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh that sounds soooo familiar where I was working!! *!@**! testers!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what is that <> ?

This compiled ok for me. all I did was removed the <> friend ostream & operator << (ostream &, const Nested &);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just after cin make a test for cin.good(). The program is adding n to total whether cin.goo() is true or not.

Or you could reset n to 0 before the cin line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what's the point of using pow() in that numerator? 1^N is always 1, so you're just wasting cpu time calculating the value of 1. You would get the same result with this? serieValue+= 1/pow(n,2.0) or this serieValue+= 1/ (n*n) , eliminating the pow() function altogether.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AFAIK the Express edition of that compiler doesn't support what you are attempting to do. I have never seen a menu option to add a data source. A couple years ago I used 2005 Pro version and it had that option. But I don't think the Express version has it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh I see. So you spent hours and hours writing code without bothering to compile it even once :icon_eek: Even experienced programmers will not do what you did.

My suggestion is to start all over again. But this time just write a little bit, compile, correct all errors, the write a little bit more. Repeat that until you are finished.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

add another int variable and increment it inside that loop -- that will count the number of iterations that loop made. Then do the math after that loop terminates.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code you originally posted does not include that header file. You need to add it after <fstream> then recompile to see how many errors disappear.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only errors I got were unresolved functions (because they were not coded, so that was no surprise) and undeclared variable numgates. Below is what I compiled using VC++ 2008 Express. What compiler are you using?

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class circuit
{
    // circuit information
	int **output;			// output of the gate
	int *flag;              // flag for every gate 
	int *count_gate;        // count for number of gates at each level
	int *rno;               // count for number of gates at each level
	int num_clauses;
	int or_output;
	std::string answer;
	int jml;
	double comb;
	int number_lines_delete;
	int CONST_INITIAL_STATES;
	int initial_states;	
    int printtestno;
	int *gate_input;		// input of individual gate
	int *input_gates;
	int *output_gates;
	int *flip_gates;
	int time_frame;         // Number of time frames to unroll the circuit
	int **pseudo_outputs;   // Correspondence betwen flip flops and PPO
	int new_states_count;
 	int count_illegal;
	int count_legal;
	int *legal_count;
	int more_states;
	int **line_read;
	int *initial_state;
	
	std::vector<int> vecvar;
	/* Storing the initial 50 reachable states */
	std::vector<int> rstates_row;
	std::vector<vector<int> >rstates;

	/* The group of correlated flip flops obtained by MLP are stored in this vector */
	std::vector<int> correlated_flops_row;
	std::vector<vector<int> >correlated_flops;
	
	/* Storing the AND/OR/NOR clauses*/
	std::vector<int> rows;
	std::vector<vector<int> >columns;
	
	std::vector<int> temporary_illegal_row;
	std::vector<vector<int> > temporary_illegal_col;
	
	std::vector<int> universal_row;
	std::vector<vector<int> > universal_column;

	std::vector<int> truth_table;
	std::vector<vector<int> > truth_table_col;
	
	std::vector<int> temp_vector;

	std::vector<int> get_value;
	// you may wish to add more function declarations (or public variables) here
	public:
	circuit(char *, char *, int );            // constructor
	
	int store_rstates(int, int, int);
	int unroll_circuit(char *, int, int);
	int writetofile(int, …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what is dnode? Where is it declared ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post the class declaration so that we know how those objects are declared

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

thats nice ancient dragon how about the total is divided by the times you input no.


long n is divided by how many times you input a no. :)

I'll leave that up for you to do. I don't want to spoil all your fun;)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you see an if statement in the code I posted? If you don't understand how it works then compile and run it yourself. When you are done typing just enter any non-numeric character, doesn't matter what you type as long as its not a digit.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Check the tree and make sure left and right both have NULL pointers at the last node.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could write a copy function to avoid the duplicate code you have

char* copy(char* to, char* from)
{
   while(*from)
     *to++ = *from++;
   *to = 0;
   return to;
}
char* cat(const char *arg1,const char *arg2)
{
    char *p = new char[strlen(arg1)+strlen(arg2)+1];
    copy( copy(p, arg1), arg2);
    return p;
}
Sky Diploma commented: Thanks-- That Really Helped. +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How do i find the month with the largest amount of rain?
You already have the array that contains the count of the number of Rs, Ss and Cs. Now all you have to do is iterate through that array and keep track of which month has the greatest number of Rs. How would you do that? Try it with pencil & paper first

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you can its best to post the code that caused the error.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 23: oops! that just lost the location of the memory that was allocated on line 13. You need to use a different pointer for incrementing and leave the original pointer unchanged.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The countNodes() returns one too many nodes -- Initialize count to 0, not 1.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Index would be similar

if(highTemp >= YrTemp[x][0])
      {
           highTemp = YrTemp[x][0];
           highIndex = x; // set index to be returned
     }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You could use any non-numeric character as the terminator.

int main()
{
    long n;
    long total = 0;
    while(cin.good())
    {
        cout << "Enter a number or 'n' to stop\n";
        cin >> n;
        total += n;
    }
    cout << "total = " << total << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>pow(+1.0, n+1)/pow(n*n,2.0);
How does (1/9) translate to the above equation? When n = 1, the above will be pow(1,2) / pow(1,2) which is 1^2/1^2 = 1. When n = 2, we get pow(1,3)/pow(4,2) which is 1/16

It looks to me your formula is completely wrong. How you get from (1/9) to (1/25) I don't know, but it doesn't work that that formula or program.

Another point about that equation -- pow(1.0, n+1) -- the result will always be 1 so the formula boils down to 1/pow(n*n,2.0)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

that's dumb.

what if he wants to add 9999 as one of his numbers

That's a common way to terminate user input, another is to type Ctrl+Z. If he needs to let the user enter 9999 then his program should choose a different number to terminate input.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to include <string> and <iostream> header files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>inData >> Paint[count].ArtistName();

You are treating ArtistName as though it were a function. Remove the () and that line will compile ok. Same with the other lines (31-35).