Dev C++ Const



NOTE: please please use #define directives or const (as needed). C language needed. I'm using dev c btw. Create an algorithm (pseudo code and flowchart) and program for the given problem below and use #define directives or const (as needed) and other arithmetic operators. To: dev-cpp-.@lists.sourceforge.net Subject: Re: Dev-C enum problem??? Hello I think I've found the problem: One of your Choices' enums is a macro. I've found DELETE defined at winnt.h. I don't know what it is used for, or how it is included, but if you delete DELETE, or rename it, your program compiles. Int strcmp ( const char. str1, const char. str2 ); The function returns 0 if both the strings are equal or the same. The input string has to be a char array of C-style string. The strcmp compares the strings in a case-sensitive form as well. LRESULT DispatchMessage( const MSG.lpMsg ); Parameters. Type: const MSG. A pointer to a structure that contains the message. The return value specifies the value returned by the window procedure. Although its meaning depends on the message being dispatched, the return value generally is ignored. Note that it is not best practice within C to use #defines for mathematical constants! Instead, as an example, you should use const double pi = 3. The #defines are a legacy feature of C.

  1. Dev C++ Constitution
  2. Devc++ Console Window
  3. Dev C++ Construction
2003-11-25 11:11:06 UTC

Dev C++ Constitution

Dev C++ Const

Devc++ Console Window

Dev C++ ConstConst

Dev C++ Construction

Hello All,
I'm experience an error that I am completely unfamiliar with. If someone
can help me, please do so. I've listed the error lines and the compile log
directly below...and for the really brave, I've placed the whole program at
the bottom.
Line 19: enum Choices { TEXTFILE = 1, UPDATE, NEW, DELETE, END };
*
*
Line 41: while ( ( choice = enterChoice() ) != END )
*** COMPILE LOG ***
Compiler: Default compiler
Building Makefile: 'C:compileMakefile.win'
Executing make...
make.exe -f 'C:compileMakefile.win' all
g++.exe -c main.cpp -o main.o -I'C:/Dev-Cpp/include/c++'
-I'C:/Dev-Cpp/include/c++/mingw32' -I'C:/Dev-Cpp/include/c++/backward'
-I'C:/Dev-Cpp/include' main.cpp:19: parse error before numeric constant
main.cpp: In function `int main()':
main.cpp:41: `END' undeclared (first use this function) main.cpp:41: (Each
undeclared identifier is reported only once for each
function it appears in.) make.exe: *** [main.o] Error 1 Execution
terminated
** END COMPILE LOG ***
Thanks.
Joseph
*** MAIN.CPP ***
// this program reads a random access file sequentially,
// updates data already written to the file, creates new
// data to be placed in the file, and deletes data already in the file
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
using namespace std;
struct clientData
{
int accountNumber;
char lastName[ 15 ];
char firstName[ 10 ];
double balance;
};
int enterChoice();
void textFile( fstream& );
void updateRecord( fstream& );
void newRecord( fstream& );
void deleteRecord( fstream& );
void outputLine( ostream&, const clientData & );
int getAccount( const char * const );
enum Choices { TEXTFILE = 1, UPDATE, NEW, DELETE, END };
int main()
{
fstream inOutCredit( 'credit.dat', ios::in | ios::out );
if ( !inOutCredit )
{
cerr << 'File could not be opened.' << endl;
exit( 1 );
}
int choice;
while ( ( choice = enterChoice() ) != END )
{
switch ( choice )
{
case TEXTFILE:
textFile( inOutCredit );
break;
case UPDATE:
updateRecord( inOutCredit );
break;
case NEW:
newRecord( inOutCredit );
break;
case DELETE:
deleteRecord( inOutCredit );
break;
default:
cerr << 'Incorrect choice n';
break;
}
inOutCredit.clear(); // resets end-of-file indicator
}
system('pause');
return 0;
}
// prompt for and input menu choice
int enterChoice()
{
cout << 'nEnter your choice' << endl
<< '1 - store a formatted text file of accountsn'
<< ' called 'print.txt' for printingn'
<< '2 - update an accountn'
<< '3 - add a new accountn'
<< '4 - delete an accountn'
<< '5 - endl programn? ';
int menuChoice;
cin >> menuChoice;
return menuChoice;
}
// create a formated text file for printing
void textFile( fstream &readFromFile )
{
ofstream outPrintFile( 'print.txt', ios::out );
if ( !outPrintFile )
{
cerr << 'File could not be opened.' << endl;
exit( 1 );
}
outPrintFile << setiosflags( ios::left ) << setw( 10 )
<< 'Account' << setw( 16 ) << 'Last Name' << setw( 11 )
<< 'First Name' << resetiosflags( ios::left )
<< setw( 10 ) << 'Balance' << endl;
readFromFile.seekg( 0 );
clientData client;
readFromFile.read( reinterpret_cast<char *>( &client ), sizeof(
clientData ) );
while ( !readFromFile.eof() )
{
if ( client.accountNumber != 0 )
{
outputLine( outPrintFile, client );
}
readFromFile.read( reinterpret_cast<char *>( &client ), sizeof(
clientData ) );
}
}
// update an account's balance
void updateRecord( fstream &updateFile )
{
int account = getAccount( 'Enter an account to update' );
updateFile.seekg( ( account - 1 ) * sizeof( clientData ) );
clientData client;
updateFile.read( reinterpret_cast<char *>( &client ), sizeof( clientData
) );
if ( client.accountNumber != 0 )
{
outputLine( cout, client );
cout << 'nEnter charge (+) or payment (-): ';
double transaction; // charge or payment
cin >> transaction; // should validate
client.balance += transaction;
outputLine( cout, client );
updateFile.seekp( ( account - 1 ) * sizeof( clientData ) );
updateFile.write( reinterpret_cast<char *>( &client ), sizeof(
clientData ) );
} else
{
cerr << 'Account #' << account << ' has no information.' << endl;
}
}
// create and insert new record
void newRecord( fstream &insertInFile )
{
int account = getAccount( 'Enter new account number' );
insertInFile.seekg( ( account - 1 ) * sizeof( clientData ) );
clientData client;
insertInFile.read( reinterpret_cast<char *>( &client ), sizeof(
clientData ) );
if ( client.accountNumber 0 )
{
cout << 'Enter lastname, firstname, balancen? ';
cin >> client.lastName >> client.firstName >> client.balance;
client.accountNumber = account;
insertInFile.seekp( ( account - 1 ) * sizeof( clientData ) );
insertInFile.write( reinterpret_cast<char *>( &client ), sizeof(
clientData ) );
} else
{
cerr << 'Account #' << account << 'already contains information.'
<< endl;
}
}
// output a line of client information
void outputLine( ostream &output, const clientData &c )
{
output << setiosflags( ios::left ) << setw( 10 )
<< c.accountNumber << setw( 16 ) << c.lastName
<< setw( 11 ) << c.firstName << setw( 10 )
<< setprecision( 2 ) << resetiosflags( ios::left )
<< setiosflags( ios::fixed | ios::showpoint )
<< c.balance << 'n';
}
// get an accoun number from the keyboard
int getAccount( const char * const prompt )
{
int account;
do
{
cout << prompt << ' ( 1 - 100 ): ';
cin >> account;
} while ( account < 1 || account > 100 );
return account;
}