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

I don't know about you all, but I love pies and I love cakes. But put them together, and what do you get? A Cherpumple Pie Cake Yuuuuuuummmmmmm!;)

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

Start out by creating a CLR Windows Forms project. That will generate the basic
dialog box on which you can drag&drop controls, such as edit and list boxes. Once you have the dialog visually set up the way you want it you can double-click a control and the IDE will create a startup event handler function for you. Then all you have to do is add your code in those event handlers.

CLR/C++ is not the same as c++ and you will have to learn some additional statemeents about .NET.

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

There is no such thing as c++ 4.5

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

what did you enter for a and b, and what were the results?

mitrmkar commented: A good question +7
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Start with this:

#include <iostream>
#include <fstream>

using std::cin;
using std::cout;
using std::iostream;
using stdLLifstream;

int main()
{

   // your program goes here

}

Next you will have to create a list of questions and their four possible answers, save them in a text file or just hard code them in your program.

Select one of the questions at random, display the question and four possible answers. Then ask the user to enter a,b, c or d (one of the 4 possible answers). Repeat as often as necessary so that the user can win a million dollars.

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

You don't have to read it all at one time, but you do have to read all of it. Use a loop to read unwanted fields and just toss them out

char buf[255];
// read first 10 fields
int i;
for(i = 0; i < 10; i++)
   fscanf(fp, "%s,",buf);  // something like this
// now read the times.  After that, 
// call fgets() to read the remainder of the line
//

Another way to do it is to read the entire line with fgets() then use strtok() to split it into its individual fields, ignoring unwanted fields at the beginning of the line.

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

You need two nested loops, not just one. The first loop counts from 0 to num then the inner loop counts from 0 to the value of the outer loop, something like this

for(int i = 0; i < num; i++)
{
    for( int j = 0; j <= i; j++)
    {

    }
}
theoryforlife commented: Great for explaining why to include the function +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Entry level programmers are not expected to be as competent as those with a year or more experience. Just show your prospective employers that you know the basics and you will be oki. As for the number of languages, just concentrate on one or two so that you can gain expert knowledge of them. You don't want to be "Jack of All Trades, Master of None.". But you have to fullfill your school's requirements. I would say C and/or C++, Java and SQL would be good start. If you have time you should branch out into web scripting too.

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

I heard that same argument 25 years ago. Yet there are still a lot of people and companies who need programming work but either don't want to do it themselves or don't have the time. freelance jobs are secure in the forseeable future.

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

This is not c++ -- it is CLR/C++ which is another language that was derived from c++. And yes, it is very easy to add the console code to the CLR project -- call the code in the button or menu event handler. The console code won't be able to use cout or cin because there is no console window, but otherwise all other code should work ok.

As for your first question, you have to create another form, say Form2, then display that form in the menu event handler.

private: System::Void availabilityToolStripMenuItem1_Click(System::Object^  sender, System::EventArgs^  e) {			 

     Form2^ f2 = gcnew Form2;   // allocate memory for Form2
     this->Hide();      // hide Form1
     f2->ShowDialog();  // run Form2
     this->Show();      // after Form2 finishes, show Form1 again

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

Your compiler is a 16-bit compiler that only runs under MS-DOS and knows nothing about long file names, such as names with spaces. It will be impossible that compiler to create a new directory that contains spaces like "Program Files" or names longer than 8 characters and 3 character extension.

Check your spelling -- if you are going to display something on the screen it should at least be spelled correctly.

jonsca commented: Good point. I had thought that about the prompt also. +6
royng commented: Good and detail solution +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One way would be to use non-standard _kbhit() from conio.h

while( !_kbhit() )
{
  // do stuff here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'd replace that old compiler with a newer one, such as Code::Blocks or VC++ 2010 Express. Dev-C++ has not been supported or updated for many years now, and the distribution contains an old obsolete version of MinGW compiler.

Aside from that, the error you got was probably because that header file was not in the same directory as the rest of the source code files.

Attached is the project I created using VC++ 2010 Express. I deleted all the compiler-generated files to make the *.zip file smaller

lexusdominus commented: very informative and helpful +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>header_name=(char *) malloc ((strlen(header_name)+1)*sizeof(char));

You are not thinking -- use your head for something other than a hat rack. variable header_name is nothing more than an uninitialized pointer which just points to some random location. It is not a null-terminated string, so why are you calling strlen() on it? That makes as much sense as trying to put a tire on the bumper of a car.

If you want that function to work you will have to rearrange its logic. The lines of the program have to be in the order that they are to be executed.

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

They might not like what the current government does, but looks to me like its a recipe for disaster. Egypt could wind up with something much worse than they have already.

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

Agree, I think that problem has been reported before, not long after those two buttons were introduced. Once the up or down button has been pressed there is no way to cancel the vote, such as when you pressed the wrong button.

It's probably one of those things low on Dani's priority list.

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

MS-Windows only runs on x86 or Intel based computers. Therefore win32 and x86 are the same thing.

>> If I chose x64, it doesnt run an any computer that doesnt have a 64bit OS.. If I press x32, It doesnt run on a x64 computer

I use 64-bit Windows 7 and run a lot of 32-bit programs. VC++ 2010 Express is 32-bit and generates only 32-bit code. Works without a problem on my computer.

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

Yes, I agree with Sfuo -- you can add MS-Windows gui to a console application. Here's how to do it from the console program. What I did was create a win32 windows application then copied the *.cpp, *.h, *.rc and other resource files into the console project folder, then add all those files to the console project. I even left tWinMain() in tact, just as the VC++ 2010 Express IDE generated it. I changed nothing in the GUI program. Then I put the GUI startup into its own thread so that the GUI would run at the same time as the console program.

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{

    HMODULE hInstance = GetModuleHandle( (char *)lpParameter);
    _tWinMain(hInstance,NULL,(char *)lpParameter,SW_SHOW);
    return 0;
}

int main(int argc, char* argv[])
{
    DWORD dwCounter = 0;
    DWORD dwThreadID = 0;
    HANDLE hThread =  CreateThread(NULL,0,ThreadProc,argv[0],0,&dwThreadID);
    while(true)
    {
        // your actual console program may not have to call WaitForSingleObject()
        // I just put it here so that I could easily see the console displaying
        // something while the gui is running.
        DWORD dwReturn = WaitForSingleObject(hThread,2000); // 2 second wait
        if( dwReturn == WAIT_OBJECT_0 )
            break;
        cout << "counter = " << dwCounter << '\n';
        ++dwCounter;
    }
    cout << "All done folks\n";
    cin.get();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>... Could VC++ just tell me?!?
I think it did -- you just were not listening.

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

line 40 is wrong -- as posted it is just a simple global function, which is unrelated to the Tree class. You need to add Treed:: before the function name, similar to what you did on line 29.

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

A tripple pointer can mean one of two things:
1. A pointer to a 2d array. In this case the 3d star is not used in the calculation

2. A 3d array -- each dimension is calculated like I mentioned previously.

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

Thanks for the clarification -- just goes to show how little I really know about it :)

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

add another variable to keep track of the element number and use it just like you do highTemp variable that appears on line 6 of the code you posted.

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

The last post was from someone named Brian Muth, and suggested opening the file with "rb+", which is what you want to do.

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

compilers will leave holes in the structure if its data members are not aligned properly. One reason for adding padding members is to insure the structure compiles the same with every compiler and operating system and to make transmission across tcp/ip more reliable.

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

The example you posted probably works because child class has no data members, just one method. When you allocate a class with new the compiler only allocates data because the methods are already in memory. If you add some data members to child class I'll bet the program won't work right when trying to access the data.

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

Mike: it took you over 33 minutes to press the Post Reply button??

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

>> The <string> library has an "at" function which lets you check
Yes it does, but it is more convenient to just use the [] operator, and what about the tabs that may be in the string? Those have to be ignored too, which is why isspace() needs to be used.

int letterCounter = 0;
    for (int i = 0; i < text.length(); i++)
    {
        if (!isspace(text[i]))
        {
            letterCounter++;
        }
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1>------ Build started: Project: test1, Configuration: Debug Win32 ------
1> test1.cpp
1>c:\dvlp\unmanaged\test1\test1.cpp(2): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Notice the second line tells you what's wrong. Then if you removed the .h file extension your compiler should have given you these messages

1>------ Build started: Project: test1, Configuration: Debug Win32 ------
1>  test1.cpp
1>c:\dvlp\unmanaged\test1\test1.cpp(51): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\dvlp\unmanaged\test1\test1.cpp(55): warning C4996: 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getch. See online help for details.
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\conio.h(128) : see declaration of 'getch'
1>  LINK : c:\dvlp\unmanaged\Debug\test1.exe not found or not built by the last incremental link; performing full link
1>  test1.vcxproj -> c:\dvlp\unmanaged\Debug\test1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I have a book here "Microsoft Visual C++.net" with all the installation and whatnot with it. It doesnt use the normal cin and cout but used Console::WriteLine and what not.

Because that is not c++ -- its a different language called clr/c++, which is a derivative of c++. If you want to learn c++ then create a win32 console application, not a CLR project.

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

So how can I do that, please

Well, give it a shot and start to program. Start out simple -- first generate the list of random numbers. Only when you are finished with that -- and the program compiles correctly and tested -- should you begin the second part. The second part is to split the file into two smaller files.

We are not going to write the program for you -- just start writing, compiling and testing. You can always post the code you have written here is you come across a problem that you do not understand.

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

According to this article the internet will run out of IP addresses some time in 2011. Will the internet stop working then? Most likely not, its just that no new ip address can be assigned until IPv6, for "version six" is adopted, and will add more digits to the ip addressing scheme.

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

The instructions are not clear enough. Do you have to generate two files that contain random numbers, such use a merge-sort altorithm to merge them into one sorted file? Or generate one large file, split it into two smaller files, then use merge-sort ?

You should start by reviewing these links

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

I just gave you an example.

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

If you want to keep the data for each line separated then use a 2d array or 2d vector and declare it above that while loop that starts on line 20. float data[25][20]; is large enough to hold the data for 25 lines of code. Change the 25 to whatever you need for the data file the program is reading.

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

you have to tell the compiler that ifstream and ofstream are in std namespace. There are a couple ways to do that

#include <fstream>

using std::ifstream;
using std::ofstream;

or this

#inclue <fstream>
#include <iomanip>

int main()
{
   std::ifstream fin;
   std::ofstream fout;
}
beejay321 commented: think that did the trick thanks! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

rand() will return a random number. If you want to restrict it to a set of numbers between 0 and N than use the mod % operator, such as int x = rand() % N;

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

Did you compile and run that little program? If not, you should do it now so that you gain better understanding of what it does.

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

>>ohh, ok ancient the >> make read just the numbers,and not the line who begins with #(char variable) correct?

Yes, and that's why I added the getline() just before the while loop

What I posted will just read all the numbers, one at a time. You will have to add code that uses those numbers for something. I don't understand what you need to do with those numbers.

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

The string line is correct -- its derived from std::string declared in <string> header file. You should compile and run the program yourself to see what >> does.

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

int main () {
  std::string line;
  std::ifstream is;
  float num;
  std::cout << "Enter the name of an existing text file: ";
  std::getline(std::cin, line);
  is.open (line.c_str());        // open file

  // get the first line
  std::getline(is,line);
  // how get all the rest of the numbers
  while( is >> num)
  {
     std::cout << num << '\n';
  }
  is.close();           // close file
  
  cin.get();
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13: variable str was declared on line 3 to have only 3 characters, yet you expect someone to type up to 256???? Also, use cin.getline(), not cin.get() because getline() will allow you to enter spaces.


The syntax in the loop is incorrect. ifstrezam will make all conversions for you if you use >> operator.

float num;
std::string line;
getline(is,line); // get the first line, e.g. #S 1
while( is >> num )
{
   cout << num << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

USERPROFILE environment variable works for me with Windows 7

#include <iostream>
using std::cout;
using std::cin;

int main()
{
    char* p = getenv("USERPROFILE");
    if( p )
        cout << p << '\n';
    else
        cout << "USERPROFILE not found\n";
    cin.get();
}
MasterGberry commented: Perfect C++ Example :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

SetBouds() will move the window to the x and y coordinates you specify.

There is probably more than one way to do it, but this is how I solved the problem.

1. In Form2 add a public data member of type Rectangle, e.g. Rectangle r; 2. In Form1, in the OnButtonClick event handler

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 Form2^ f2 = gcnew Form2;
                 f2->r = ClientRectangle; // set the Rectangle object in Form2
                 this->Hide();
                 f2->ShowDialog();
                 this->textBox1->Text = f2->GetTextBoxString();
                 this->Show();
             }

3. In Form2,

private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {

                 SetBounds(r.Right+1,r.Top,r.Height,r.Width);
             }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

0 and '\0' are identical and can be used interchangealy, which one you use is only a matter of programming style.

jonsca commented: Thanks. +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb. I too retired from computer programming about 4 years ago because I was just getting too old to put up with all the stress that is involved. Let the younger people do it :)

We need experienced coders around here to help younger people with their problems,so feel free to answer all the threads you feel you are qualified to give your expert advice. Actually that's the reason I have such a high post count because I've spent some time to do just that.

AndreRet commented: Bragger! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The function you are calling is UNICODE function. LPWSTR is a pointer to a unicode string, not an ascii string. You need to declare the string like this: wchar_t ConvertTime[9]; , or if you want to compile the program as either ascii or unicode then use the macro TCHAR: TCHAR ConvertTime[9]; and include <tchar.h> header file.

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

It meant to use the ShowDialog() method of a specific Form, as in the example I posted. Try it before complaining.

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

Here is an example where Form1 copies the text from Form2 after Form2 closes. In Form2.h I added a public method that return the String from its textBox1 text control. Similar technique can be used for all of the controls on Form2.

Form2.h

public:
        String^ GetTextBoxString() { return textBox1->Text; }

Form1.h This method is envoked when a button control is clicked.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 Form2^ f2 = gcnew Form2;
                 this->Hide();
                 f2->ShowDialog();
                 this->textBox1->Text = f2->GetTextBoxString();
                 this->Show();
             }
    };
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Plus, I do not believe that the world will end on exactly 12/12/12

I agree -- did the world come to an end on 1/1/11? Noooo. Besides, someone in a tabloid last month claimed it will come to an end in Sep 2011. So you all better get your personal lives in order because you don't have much time left :)

jember commented: lol xD +0