WolfPack 491 Posting Virtuoso Team Colleague
#include <iostream>
// #include <stdlib.h> // You dont need this
using namespace std;

// This program reads in five numbers, find their sum, then prints the numbers in reverse.//
int main ()
{
	const int numlist = 5;
	int num[ numlist];
	int total = 0 ; // Remember to initialize variables
	int numcount; 
	for (numcount = 0; numcount < numlist; numcount++)
	{
		cout << "Enter number " << numcount << ": ";
		cin >> num[numcount];
	}
	for ( int i =0; i< numlist; i++)
	{
		total = total + num[i];
	}
	cout << "\nThe total of the numbers are: " <<total << endl;
	// To Print the numbers in reverse
	for ( int i =numlist - 1 ; i>=0; i--)
	{
		cout << num[ i ] << endl;
	}
	
	return 0;
}
WolfPack 491 Posting Virtuoso Team Colleague

is they a way of getting a set of co-ordinates on the screen? I want it the fursthers right but a very small cirlce. I've been filling it with some radmon but logical numbers and not getting very far

Sorry but I dont know what you mean. What were the values you used and what do you mean by you didnt get very far? Maybe a problem with the mapping mode. Look for CDC::MapMode()

Can I chose not to fill the circle? so its just an outline? Also can I draw lines with this code? or is that something to do with the paintbrush?

Yes you can. And yes, it has to do with the paintbrush. And I think also with the CPen Object you select. Go through the documentation for CPen and CBrush in MSDN.

Also can I change the background colour of the entire mfc window? I can't find that in the properities of the dlg box anywhere.

Maybe not in Visual C++ 6.0. But I think it was possible in Visual Studio .NET. Anyway do it programmatically. You could probably do it by using the CDC::SetBkColor() method. You will have to search for the COLORREF datatype also.

WolfPack 491 Posting Virtuoso Team Colleague

Just do this.

void CHangmanDlg::print
( 
  int nLeftRect,  // x-coord of upper-left corner of rectangle
  int nTopRect,   // y-coord of upper-left corner of rectangle
  int nRightRect, // x-coord of lower-right corner of rectangle
  int nBottomRect // y-coord of lower-right corner of rectangle
)
{
  CDC* pcdc = this->GetDC();
  if ( pcdc)
  {
           pcdc->Ellipse( nLeftRect, nTopRect, nRightRect, nBottomRect );
           if ( this->ReleaseDC( pcdc ) > 0 )
           {
                  // Successfully Released
           }
           else
           {
                  // Error in Releasing Device Context
           }
  }
}
void CHangmanDlg::OnBnClickedCancel()
{
        CHangmanDlg::print(10, 100, 30, 140 );
	OptionsDlg dlg;
	dlg.DoModal();
}
WolfPack 491 Posting Virtuoso Team Colleague

Looks like you are trying to call the Ellipse function provided by the Windows API. Then you dont have to redefine it inside the

void classname::print()

function. Just call it like this.

void classname::print
( 
  HDC hdc,        // handle to DC
  int nLeftRect,  // x-coord of upper-left corner of rectangle
  int nTopRect,   // y-coord of upper-left corner of rectangle
  int nRightRect, // x-coord of lower-right corner of rectangle
  int nBottomRect // y-coord of lower-right corner of rectangle
)
{
  Ellipse( hdc, nLeftRect, nTopRect, nRightRect, nBottomRect );
  // Do other stuff you want inside the print function
  //...
}

Then call it like this

classname classobject;
classobject::print( hdc, 10, 100, 30, 140 );

If you get errors, better post the code.

WolfPack 491 Posting Virtuoso Team Colleague

Hello, I'm wanting to print a circle to a screen, or should I say on a form. Any ideas?

Thanks

Here

WolfPack 491 Posting Virtuoso Team Colleague

What is your operating system? Are you trying to write a Console Application or a GUI Application?

WolfPack 491 Posting Virtuoso Team Colleague

OKay here is a solution which I compiled and worked.

Use this in your main header file.

#include <windows.h> // Keep this above all the include files.
#ifndef UNICODE
#define UNICODE 
#endif
#include <TCHAR.H>

This worked at the Event where I wanted to display the message box.

TCHAR Kanji[ 10 ] = TEXT("");
_tcscpy(Kanji, TEXT("  (  )"));
MessageBox( hWnd, Kanji, TEXT("Kanji"), MB_OK);
WolfPack 491 Posting Virtuoso Team Colleague

Okay try the following, but not sure if it will work. I got a similar problem since I am working on a Japanese OS.

Try this

_tcscpy(Kanji[1][1], L"  (  )" );

The 'L' is not a mistake. Use it before the "" marks
Use

#ifndef _UNICODE
#define _UNICODE
#endif

in your header files


Then

MessageBox(hWnd, Kanji[1][1], "Kanji", MB_OK);

should work.
I could not check it so no guarantees, anyway try it and tell me what you get.

PS. Kanji should be of type TCHAR.
e.g.

TCHAR Kanji[ 2 ][ 3 ]

...

WolfPack 491 Posting Virtuoso Team Colleague

Was THAT the problem.
Here are some free versions
MSVC Compiler With IDE
MSVC Command Line Compiler

WolfPack 491 Posting Virtuoso Team Colleague

Try using the Multi Threading Debug switch /MTd and building the app.

WolfPack 491 Posting Virtuoso Team Colleague

Beats me. Looks like a compiler issue. I dont know dev-cpp so I cant help on that. It ran fine under Visual Studio.Net and Windows 2000, so get someone who knows dev-cpp to figure it out or try using VC++.

By the way, what is the Operating System?

WolfPack 491 Posting Virtuoso Team Colleague

Narue's method should work. But I could not get it to compile in my machine. It needs Windows XP or higher.

Here is a small piece of code that resizes the window. But the dimensions should be specified in pixels, not by the number of characters as in Narue's method.

You can find a Screen Clearing Program in the Code Snippets section submited by vegaseat.

#if (_WIN32_WINNT < 0x0500) // This switch is needed to make the program compile
#undef _WIN32_WINNT	    // because GetConsoleWindow needs it. See Documentation
#define _WIN32_WINNT 0x0500 // for GetConsoleWindow in MSDN.
#endif

#include <windows.h> 
 
int main() 
{ 
	system( "pause" );

	// Get the window handle for Console Window
        HWND hwnd = GetConsoleWindow( );
	int newX		= 0; // We will ignore this parameter by using the SWP_NOMOVE flag in SetWindowPos
	int newY		= 0; // We will ignore this parameter by using the SWP_NOMOVE flag in SetWindowPos
	int newWidth	= 500;	// New Width in Pixels
	int newHeight	= 100;	// New Height in Pixels
	// Position the console window so that the left and right corners are not changed but the height and width are.
	SetWindowPos(hwnd, HWND_TOP, newX, newY, newWidth, newHeight, SWP_NOMOVE); // Using SWP_NOMOVE will cause newX and new Y to be ignored

	system( "pause" );

	return 0;
}
SpS commented: Nice Post:Sunny +1
WolfPack 491 Posting Virtuoso Team Colleague

you can't access most databases, such as Microsoft Access, SQL Server, MySql, Orical, etc, with that old 16-bit Turbo C compiler. You will have to upgrade to a modern 32-bit compiler, such as Dev-C++. Then you have several options, the oldest is ODBC. google for ODBC and you will find lots of information.

Of course if you want to store simple data, then you don't really need a formal database, just store it in files.

Yeah and if you have googled for your previous assignment you can use that knowledge too. ;)

WolfPack 491 Posting Virtuoso Team Colleague

What is the database you are trying to connect to?

WolfPack 491 Posting Virtuoso Team Colleague

Hi again...I have found out how to compile and link my program, I can only do it step by step using the command line but it works like that...however Im getting lots of error messages like these...

Main.o(.text+0x28d):Main.c: undefined reference to 'GetStockObject@4'
Main.o(.text+0x311):Main.c: undefined reference to 'GetOpenFilename@4'

Im sure I have had these before when actually using the IDE...but I cant remember how to correct them...do you know how ? (these functions are within libraries that require me only to include windows.h I think...which I have)

I dont use dev-cpp, only MSVC++. Including windows.h is okay for compilation, but you should specifythe required libraries when you link them in the command prompt. For the MSVC I use something like cl main.cpp /link user32.lib gdi32.lib You would need to do something like that in dev-cpp also.

WolfPack 491 Posting Virtuoso Team Colleague

I don't know the statistics.

WolfPack 491 Posting Virtuoso Team Colleague

Using the system commands is not bad always. It is bad when you have a way of doing it through the compiler but you are using the system commands instead. This is because the system command invokes a shell process and waits will it finishes. Since starting a new process takes a lot of overhead the compiler operations are prefered.

For example
using cin.get(); is prefered to make the console wait for a the user to press a key than system("pause" ); But in the case of shutting down, since C++ does not offer a machine shutdown command you will have to use the system() command or use one of the Win32 APIs provided for that. I think it is better to use the Win32 APIs for that since the new process overhead does not apply for it.

WolfPack 491 Posting Virtuoso Team Colleague

Try something like this system("shutdown -s -t 40") It will shutdown after 40 seconds.

If you want to insert a user specified time, first prepare the command line using sprintf.

char command[ 20 ] = "";
cin >> time;
sprintf( command, "shutdown -s -t %4d", time );
system( command );
WolfPack 491 Posting Virtuoso Team Colleague

Hell... if using that is artificial using std::cout is also artificial. Use the facilities provided by the compiler, and make your life easier.

WolfPack 491 Posting Virtuoso Team Colleague

I meant do the calculations on the fly. Not a special technique. Just to mean that nothing is stored other than the results and maybe some temp variables.

It is because they may vary among different compilers(I think...). Is there an alternate method?

Good point. Yeah it will vary. There is an alternate method.
You can use

numeric_limits<int>::min()

which is found in the

<limits>

header.
Or you can use the

INT_MIN

constant found in

<climits>

.

WolfPack 491 Posting Virtuoso Team Colleague

what does the "continue" do?

The continue statement skips the rest of an iteration in the for loop and starts the other iteration.

Search for continue and break in your text book. It should have a more detailed explaination.

And what if all the inputs are negative numbers.

My code will not work if all the numbers are negative unless you initialize the values FIRST and SECOND to the largest negative integer allowed by the compiler. And neither wont the code you pasted at the start of the thread. Who wrote that code by the way?

Something like

FIRST = -4294967296; // for 32 bit integers ; i.e -2^32
SECOND = -4294967296;

You cant assign numbers smaller than this so it should work okay after that.

WolfPack 491 Posting Virtuoso Team Colleague

am afraid that "fly" technique can not be used either.

huh? How come? No arrays in it. No pointers. Nothing. Only a for loop.

WolfPack 491 Posting Virtuoso Team Colleague

Well cant you do it on the fly? Since you know the number of inputs, do something like this.

int FIRST= 0, SECOND= 0; // Variables to store the Largest and Second Largest Numbers
int input ;
for ( int i = 0 ; i < NO_OF_INPUTS ; i++ )
{
         cin >> input;
         if ( input > FIRST)
         {
                    SECOND= FIRST;
                    FIRST= input;
                    continue;
         }
         if ( input > SECOND)
         {
                    SECOND= input;
         }
}
WolfPack 491 Posting Virtuoso Team Colleague

The accessibility of the data member does not matter here. Even if you declare weight public you will not be able to use the standard constructor.

What we use the initialization list here is for initializing const data members in a class.

We have declared weight to be const. So when you define an object of type Planet, you must give a weight for it.

e.g.

Planet earth( 2000 );

In the standard constructor you use the

weight = iWeight

statement which is illegal.

The only way is to use the initialization list.

Look for this

The keyword const means that nobody can change the value of _identifier during the lifetime of the object. It is physically (or at least "compilatorily") impossible. But even a const has to be initialized some place or another. The compiler provides just one little window when we can (and in fact have to) initialize a const data member. It is in the preamble to the constructor. Not even in the body of the constructor--only in the preamble itself can we initialize a const data member. Preamble is the part of the constructor that starts with a colon and contains a comma-separated list of data members followed by their initializers in parentheses. In our preamble _identifier is initialized with the value of id.

in this page of the book I have linked. you will get a more clear idea of it's usage.

WolfPack 491 Posting Virtuoso Team Colleague

Another small thing to add that I read in the book C++ in Action .
Say you have a const member declared inside the C++ class.

class Planet
{
public:
         Planet( int iWeight);
private:
         const int weight;
}

since the weight member cant be assigned a value in a standard contructor like this

Planet::Planet( int iWeight)
{
       weight = iWeight ; // wrong
}

The only way you can do that is using an initialization list.

Planet::Planet( int iWeight):weight(iWeight) // correct
{
}
WolfPack 491 Posting Virtuoso Team Colleague

Since the question is WHO... I guess you should change "Stupid Polls" to "People who start stupid polls".

WolfPack 491 Posting Virtuoso Team Colleague

Do this

//Constructor
	CBooks(){};

You hadn't defined the Constructor. Only declared it.

WolfPack 491 Posting Virtuoso Team Colleague

Change

//Functions
	void inputBooks(string bookName, string author, int isbn, float price);
	void displayBooks(string bookName, string author, int isbn, float price);

to

//Functions
	void inputBooks();
	void displayBooks();

in the Class declaration.

WolfPack 491 Posting Virtuoso Team Colleague
#include <stdio.h>

void outputx();
void outputy();
void print_it( void(*)() ); // prototype

void outputx()
{
printf("x\n");
}

void outputy()
{
printf("y\n");
}

void print_it( void(*func)() )
{
//effectively becomes either outputx(); or outputy();
	func();
}

int main()
{
// pass the function outputx() to print_it()
print_it( outputx );

// pass the function outputy() to print_it()
print_it( outputy );
}
WolfPack 491 Posting Virtuoso Team Colleague

here is the documentation for the connect function. you can find the error constants and the way to detect failure using it.

WolfPack 491 Posting Virtuoso Team Colleague

If I have a MFC program that opens a socket connection, how would I test to see if the socket has succesfully opened or not?

almost any function in the winsock api returns the value SOCKET_ERROR in the event of failure. you only have to check this for errors. if you want details on the error number, you can use the GetLastError() function that will give the number of the error occured. Look up in the msdn link for error codes for a text explanation. you can also use the FormatMessage() function to programatically get the text explanation.


for eg.

if ( socket.function(  parameter1,... ) == SOCKET_ERROR )
       {
                  cout << GetLastError();
                  // do error processing
       }
       else
       {
                  //successfull operation
       }
WolfPack 491 Posting Virtuoso Team Colleague

as for specyfing the design of the window like a dialog box, i have found a way to do that yet using a resource editor.

I meant i have NOT found a way to do that yet. at least not in pure win32.

WolfPack 491 Posting Virtuoso Team Colleague

well, if the number of controls is small, using global variables is okay. but i prefer to create them locally inside the create function and then use GetDialogItem API to get the handles of the controls when i need them. this eliminates the need of global window handles and makes the program less messy.

the best site regarding the apis is the msdn site itself.
Individual Controls
dialogs
The list of values can be obtained in CreateWindow

as for specyfing the design of the window like a dialog box, i have found a way to do that yet using a resource editor.

WolfPack 491 Posting Virtuoso Team Colleague

Since you have functions that determine

If the year is a leapyear
how many days the month in the dates have

the rest is easy.

Your function to output the number out of the total days in an year should be something like this

int ReturnNumberOutOfTotalDays( Date date )
{
        int days = 0 ;
        // Add the maximum days in the months excluding the current month
        for ( int i = 1 ; i <= date.month - 1 ; i++ ) // assuming you started your months from 1
        {
                days += MaxDaysOfMonth( date.year, i ) ; // this function should output 29 in the case of date.year is leap and i == 2 
         }
         // Add the days gone by in this month
          days += date.day;
         return days;
}
WolfPack 491 Posting Virtuoso Team Colleague

For you people who use the command prompt in windows ( very rare I know ), the F7 key brings you a window with the command history for that session.

WolfPack 491 Posting Virtuoso Team Colleague

0xc00000fd is a StackOverflow Exception. Maybe your system can't allocate 1000025 characters from the stack. If that is the case I dont see any way other than carry out your original method ( using the new operator )of allocating it from the store.

WolfPack 491 Posting Virtuoso Team Colleague

Well I dont think you would get an error if you pass it as

m_sConnectSocket.Receive( pBuf , 1000025, nFlags)

. A void* should take any kind of pointer.
If it does still give an exception, try doing a cast.

m_sConnectSocket.Receive( (void*)pBuf , 1000025, nFlags)
WolfPack 491 Posting Virtuoso Team Colleague
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
	char no ;

	do{
		cout<<"Enter a Number"<<endl;
		cin>>no;
		cout<<no<<endl;
	} while ( no != '5' );


	system("PAUSE");
	return 0;
}

This is much better. Wont go mad at characters. But you will have to guard against multiple characters entered in the same line.

WolfPack 491 Posting Virtuoso Team Colleague

Yeah my bad. I meant

char pBuf [1000025];

I shouldn't have edited your post on the fly. Sorry about that. It should clear itself when going outof scope.

WolfPack 491 Posting Virtuoso Team Colleague

Well perni's solution should work. But why cant you use a normal array like

char pBuf = char[1000025]

? It will cleanup itself as it goes out of scope. Saves you a lot of trouble.

WolfPack 491 Posting Virtuoso Team Colleague

I ran your compiled program and yes it outputs test3. I compiled myself and ran again, but there was no test3 output. The closest I can think of is that you are modifying one source file but compiling another.

WolfPack 491 Posting Virtuoso Team Colleague

I dont think it is a sorting function at all. All it does is ask the user for a name, searches the database for a match, and once a match is found display the information the user wants to see. Nope, no sort.

WolfPack 491 Posting Virtuoso Team Colleague

Well what do you mean by running only once? I compiled and ran the program, and it ran okay. I added two patients, one doctor and printed the patient and doctor list, all by one go at the program. The other options didnt work as I think you have to implemented them.

WolfPack 491 Posting Virtuoso Team Colleague

If you want to do the detail entering and the detail printing seperately, you should define a doctor array inside the main function, and pass that function name to the two functions you are using ( Enter_Doctor_Details(), and Print_Doctor_Details() ). Better if you look up for, global scope, local scope, and passing variables to functions in your C++ book.
I have done some correcting and posted it here.

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;


class doctor
{

protected:
string newname;
string address;
int payrate;
int hours;
int age;

public:

doctor(); //constructor
virtual ~doctor();
virtual void set_Name(string itsname);
virtual string get_Name();

virtual void set_Address(string itsaddress);
virtual string get_Address();

virtual void set_Age(int itsage);
virtual int get_Age();

virtual void set_Hours(int itshours);
virtual int get_Hours();

//virtual void set_Payrate();
virtual int get_Payrate();

virtual void get_holidaypay();
virtual int calculate_pay();

}; //end of class declaration

doctor::doctor()
{
}

doctor::~doctor()
{
cout<<"Doctor Destructer called"<<endl;
}

void doctor::set_Name(string itsname){
newname=itsname;
}
string doctor::get_Name(){
return newname;
}

void doctor::set_Address(string itsaddress){
address=itsaddress;
}

string doctor::get_Address(){
return address;
}

void doctor::set_Age(int itsage){
age=itsage;
}

int doctor::get_Age(){
return age;
}

void doctor::set_Hours(int itshours){
hours=itshours;
}

int doctor::get_Hours(){
return hours;
}

//void doctor::set_Payrate(int itspay){
//payrate=itspay;
//}

int doctor::get_Payrate(){
return payrate=100;
}

void doctor::get_holidaypay(){
cout<<"You Have weekend off "<<endl;
}

int doctor::calculate_pay()
{
	return (get_Payrate()*hours);
}


//Junior Doctor Class

class junior: virtual public doctor
{
	public:
	junior(){}
	virtual ~junior();
	virtual void get_holidaypay();
	virtual int get_Payrate();


	};

	void junior::get_holidaypay()
	{
	cout<<"You Have 2months off "<<endl;
	}

	int junior::get_Payrate(){
	return payrate=200;
	}
WolfPack 491 Posting Virtuoso Team Colleague

try

"C:\\q.txt"

as the file name.

WolfPack 491 Posting Virtuoso Team Colleague

Now let me see -- which is more recent compiler, 2003 or 2005?

Now let me see -- which came first? World War 1 or World War 2? :cheesy: ehehehe.

Well if you think you have mastered C++ I dont think it is difficult to migrate to a different language. After all the concepts are in place and you only have to learn a different syntax of doing things.
And just in case you didnt know, the Visual Studio 2005 is available for C#/C++, Java, VB for free download at the microsoft website. There are a lot of material in the web, so start having a look at all the languages.
And in any case, continue on your GUI programming too. Do that in C++ as there are a lot of new concepts to that as well. Later try doing that in the other languages.

WolfPack 491 Posting Virtuoso Team Colleague

Well you got a strange compiler, mine outputs hello, hi...

Yeah I just ran it. So does mine.

allocating a new char is just a memory leak since the pointer gets overwritten in the next operation (se above post).

yeah thought as much. Anyway got the desired output ( but i know it is bad code). Tried calling delete on it, but that does not also work. Why is that?

WolfPack 491 Posting Virtuoso Team Colleague

unichar can be more than 2 bytes? I thought it was always 2 bytes.

WolfPack 491 Posting Virtuoso Team Colleague

try this

int top=0;
	
int filewrite(void) 
{
			
	int i;
	char years[4];
	char ch[2];
	for(i=top;i<1;i++)
	{
		printf("Press Y to Continue or N for Menu");
		gets(ch);
		printf("Enter the artist: \n");
		gets(cd[i].artist);
		printf("Enter the album: \n");
		gets(cd[i].album);
		printf("Enter label name: \n");
		gets(cd[i].label);
		printf("Enter year: \n");
		gets(cd[i].year);
		printf("Enter the genre of music: \n");
		gets(cd[i].genre);		
	}
	
	top=i;
}
	
	
	
	
	/*************************************************************/
void main(void)
{
  int c;
  
 
  while( ( c = menu_select() ) !=5)
   
	     switch(c)
		 {
		 case 1:
			  filewrite();
			  		break;
	 	default:
		  		break;
		 }
 }
WolfPack 491 Posting Virtuoso Team Colleague

Define the Constructors for junior and consultant.

junior::junior()

and

consulant::consultant()

, or remove the

junior();

and

consultant();

lines in the class declarations.