|
In other words a calculator ? Do you know how to do the following:
1/ read input from the user
2/ create an array
3/ parse a string ( I presume this is what ch2int will do, parse for an operator and a number )
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
main.cpp
use getline to read the expressions. each expression will consist of one operatorand two operands. the operands will be intergers. invoke the function eval to evaluate the expression and store both the expression and result into arrays. next, sort the expressions and results in descending order of results and printthem out. allow for a maximum of 25 expressions. continue this process until the user selects an option to exit.
|
|
|
|
|
And how much of this do you know how to do ? Do you know how to read in the line ? Do you know how to evaluate the result to extract the numbers ? What are you allowed to use ( can you use STL for example ).
Console app or not, Nish is right and your teacher needs shooting. There is no reason this can't all be done in one class, in one .cpp file.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
I know he need shot. i don't understand any of what you said and this project is due tomorrow. I had a freind who said he would help but he had to go home to his grandfather funeral yesterday so I am needing some help.can some one help
|
|
|
|
|
I said:
And how much of this do you know how to do ? Do you know how to read in the line ? Do you know how to evaluate the result to extract the numbers ? What are you allowed to use ( can you use STL for example ).
You said:
i don't understand any of what you said and this project is due tomorrow.
Bloody hell. I am astounded that it didn't occur to you before now that you were not learning anything and that you should be. What course are you doing ? Is this the only computing component ?
You're saying this course has had no marking up until now, and if you write this program you will pass ? Is everyone in the class in the same boat ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
6 people dropped the course the other day, and we can use anything we want. as far as I can tell the teacher knows dick about c++, up until this point it was goin ok, the project seemed fairly simple, then bam this one and the teacher is so confusing. and the reaosn i took the corse was to learn c++. I knbow asp and html and web programming, so I thought I would learn a real programming language. and I get stuck with the teacher who know nothing. or at least he can't convey it!!!
|
|
|
|
|
thank guys for all the help, I really appercaite it hope fully I can figure something out in the morning. but the code from nish will help greatly. agina thank you very much. if you have any more coments or code please send them to mrthump@hotmail.com again thank you very much!!!!!
|
|
|
|
|
It must have been one hell of a short course if it had 'gone well' but you didn't know any of the things I asked you. I really recommend you buy some good books, and as for this course, that you let people in charge know that the teacher has let you down.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
I've done a simple version of eval for you. You can modify it to suite your needs.
int eval(char *s)
{
int res=0;
char *a;
if((a=strchr(s,'+'))==NULL)
if((a=strchr(s,'-'))==NULL)
if((a=strchr(s,'*'))==NULL)
if((a=strchr(s,'/'))==NULL)
if(a==NULL)
return 0;
char *b=a+1;
int v2=atoi(b);
switch (a[0])
{
case '+' :
res=atoi(s)+v2;
break;
case '-':
res=atoi(s)-v2;
break;
case '*':
res=atoi(s)*v2;
break;
case '/':
res=atoi(s)/v2;
break;
}
return res;
}
Regards
Nish
Sonork ID 100.9786 voidmain
|
|
|
|
|
there will be three source files: main,eval and ch2int.
OUCH!!!
If your teacher said that, then you are right as to his being a moron. He prolly took it out of some old C text book that was written by a similar moronic author.
Three source files for a program to evaluate a simple mathematic expression!! and what's more! Even their names are specified. One of those names is ch2int which prolly means write a source file to convert char to int [which is auto-done by C-compilers as far as I know]
Like Christian said, GO COMPLAIN ABOUT THAT IDIOT
Nish
Sonork ID 100.9786 voidmain
|
|
|
|
|
the file is a console app.
|
|
|
|
|
I find myself needing to read/write all of the class member variables to and from an ini file. The ini file contains data for other classes as well.
I'm looking for a cool way do this. I need a member variable of whatever type, a name for that variable in the ini file, and read/write routines that work off of some kind of list structure. Any ideas?
Todd Smith
|
|
|
|
|
How about Get/WritePrivateProfileStruct()?
---
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|
That doesn't really work for what I need.
So far what I've come up with is to use a #define and create a .inc file which I will include in a .h and a .cpp file. The .inc will do different things when it's in the .h vs. in the .cpp. When I include the .inc in a .h file it will declare the member variables. When I include the .inc in a .cpp file it will create code to add the member variables along with a name to a map or something. I haven't worked out the details yet.
Todd Smith
|
|
|
|
|
If you're using MFC and your object is derived from CObject you can use CArchive with CMemFile, then save the contents of CMemFile to .ini using CWinApp::[Get|Set]ProfileBinary.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
What you're after is called reflection, the ability to access in runtime to the structure of a class. Efforts devoted to achieve some sort of reflection in C++ are usually very far-fetched (look for OpenC++ and Meta Object Protocol (MOP), for instance). Nevertheless, it is possible that some kind of library exists fith more modest objectives that suits your needs.
Good luck
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
How can I drag icon in CListCtrl ? Just like Windows Desktop!
|
|
|
|
|
See MFCDRAG and maybe LISTHDR samples in MSDN. Maybe it will help.
|
|
|
|
|
Does anyone know how to detect if a item was checked or unchecked in a CTreeCtrl? I took a look at the CTreeCtrl and it seems that there are no messages for this kind of thing.
|
|
|
|
|
Sorry - no special notification for that. You'll have to handle WM_LBUTTONDOWN and use CTreelCtrl::HitTest. If returned flags have TVHT_ONITEMSTATEICON bit set, it was a click on checkbox.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I have an assignment about writing 2 dimensional arrays class Array2D, but I don't know the syntax for using int *iptr and int **array2D to dynamically allocate memory. The following is my program. The class interface and main driver given as it is. I couldn't really find the error on my class Array2D implementation part. Please help me out.
#include <iostream>
using namespace std;
#include <iomanip>
#include <cstdlib>
#include <cassert>
#include "PA_02.h"
//Output the array in row & column format (table format)
//Overloaded output operator for class Array2D
ostream &operator<<( ostream &out, const Array2D &obj )
{
for ( int i = 0; i < obj.rows; i++ )
{
for ( int j = 0; j < obj.cols; j++ )
out <<setw(10)<< obj.array2d[i][i];
="" out="" <<="" "\n"="" <<endl;
="" }
=""
="" return="" out;
="" input="" the="" entire="" array="" contents
="" overloaded="" operator="" for="" class="" array2d
="" istream="" &operator="">>( istream &in, Array2D &obj )
{
cout<<"Enter array values, one row at a time:\n"<<endl;
for="" (="" int="" i="0;" <="" obj.rows;="" i++="" )
="" {
="" cout<<"enter="" column="" values="" row="" "<<="" <<":\n"<<endl;
="" j="0;" obj.cols;="" j++="" cout="" <<"\nenter="" value="" ("="" <<="" <<"="" ,"="" <<")="" :";=""
="" in="">> obj.array2D[i][j];;
}
}
cout<<"\n\nInput complete\n"<<endl;
return="" in;
="" }
="" initialization="" and="" termination="" methods
=""
="" dynamically="" create="" an="" initialized="" array,="" contents="" will="" be="" to="" value
="" array2d::array2d(="" int="" r,="" c,="" value="" ):rows(r),="" cols(c)
="" {
="" i,="" j;="" iptr="new" int[="" r="" ];
="" assert(="" !="0);
" array2d="&iptr;
" for(="" i="0;" i<r;="" i++="" )
="" j="0;" j<c;="" j++="" array2d[i]="new" int[j];
="" );
="" }
="" }=""
="" initialize="" array="" equals="" 0
="" for="" (="" <="" r;="" c;="" array2d[i][j]="value;
" }
="" the="" copy="" constructor
="" const="" &rhs="" )="" :="" rows(="" rhs.rows),=""
cols(rhs.cols)
="" j;
="" rows="" rows;="" j<cols;="" rhs="" into="" object
="" cols;="" assignment="" operator="" (performs="" assignment)
="" &array2d::operator="(" j,="" i;
="" if="" check="" self="" assignment
="" delete="" []="" iptr;
="" cols="" array2d;
="" i<rows;="" *this;
="" clean="" up="" (e.g.="" allocated="" memory)
="" array2d::~array2d(="" void="" cout<<"\ndestructor="" called"<<endl;
="" =set="" get="" methods.="" explicitly="" whether="" index="" is="" within="" bounds="" of="" array
="" set="" item="" in="" at="" location(="" row,="" col="" ).
="" returns="" false="" out-of-bounds,="" else="" true
="" bool="" array2d::set(="" &new_item,="" if(="" row="">0 && col>0 )
{
for( int i=0; i<row; i++="" )
="" {
="" for(="" int="" j="0;" j<col;="" j++="" array2d[i][j]="new_item;
" }
="" return="" true;
="" else
="" false;
=""
="" }
="" get="" an="" item="" in="" the="" array="" at="" location="" (="" row,="" col="" ).
="" returns="" false="" if="" index="" is="" out-of-bounds,="" else="" true.
="" bool="" array2d::get(="" &item,="" )="" const
="" if(="" row="">0 && row<=rows )
{
if( col>0 && col<=cols )
{
for( int i=0; i<row; i++="" )
="" {
="" for(="" int="" j="0;" j<col;="" j++="" array2d[i][j]="item;
"
="" }
="" return="" true;
="" else
="" false;
="" }
="" returns="" the="" length="" of="" array
="" array2d::size(="" void="" )="" const
="" (="" sizeof(="" array2d[rows][cols]="" );
="" number="" rows
="" array2d::getrow(="" rows;
="" columns
="" array2d::getcol(="" cols;
="" compare="" this="" array="" with="" <rhs=""> for equality. Two arrays are equal if
//their
//rows, and cols are equal and all the elements are equal
bool Array2D::operator==( const Array2D &rhs ) const
{
if ( rows != rhs.rows && cols != rhs.cols )
return false; //arrays of different size
for ( int i = 0; i < rows; i++ )
{
for ( int j = 0; j < cols; j++ )
if ( array2D[i][j] != rhs.array2D[i][j] )
return false; //arrays are not equal
}
return true;
}
//Compare this array with <rhs> for inequality
bool Array2D::operator!=( const Array2D &rhs ) const
{
if ( rows == rhs.rows && cols == rhs.cols )
return false;
for ( int i = 0; i < rows; i++ )
{
for ( int j = 0; j < cols; j++ )
if ( array2D[i][j] == rhs.array2D[i][j] )
return false;
}
return true;
}
//Overload () to allow use of ( i, j ) notation ( leftvalue )
int &Array2D::operator()( int i, int j )
{
if ( i >= rows || j >= cols )
cout<<"out of bounds"<<endl;
="" return="" array2d[i][j];
="" }
="" overload="" ()="" to="" allow="" use="" of="" (="" i,="" j="" )="" notation="" rightvalue="" )
="" const="" int="" &array2d::operator()(="" const
="" {
="" if="" i="">= rows || j >= cols )
cout<<"out of bounds"<<endl;
return="" array2d[i][j];
="" }
="" utility="" functions
="" returns="" true="" if="" <index=""> is within range, else false
bool Array2D::in_range( int r, int c ) const
{
if ( r < 0 || r >= rows && c < 0 || c >= cols )
return false;
else
return true;
}
//Perform dynamic memory allocation
void Array2D::allocate( void )
{
rows = ( rows>0 ? rows );
cols = ( cols>0 ? cols );
iptr = new int[ rows ];
assert( iptr != 0 );
array2D = &iptr;
for( int i=0; i<rows; i++="" )
="" {
="" for(="" int="" j="0;" j<cols;="" j++="" array2d[i]="new" int[="" ];
="" assert(="" !="0" );
="" }
=""
="" }
--------------------------------------------------------------------------------
#include="" <iostream="">#include <cassert>
#include "PA_02.h"
#include "a2D.cpp"
using namespace std;
int main()
{
Array2D a1( 2, 3, 5 );
Array2D a2 = a1;
Array2D a3, a5( 4, 2, 3 );
Array2D a4( a3 );
//Test the << operator
cout<<"\nPrinting a1 ...\n"<<a1;
cout<<"\nprinting="" a2="" ...\n"<<a2;
="" a3="" ...\n"<<a3;
="" a4="" ...\n"<<a4;
="" a5="" ...\n"<<a5;
="" test="" the="">> operator
cin>>a3;
cout<<"\nPrinting a3 ...\n"<
|
|
|
|
|
You could save a lot of time by replacing the element of your matrix in a vector : let say you have a mxn matrix you just allocate a vector of size mn.
you can access the elements easily e.g. array[i*m+j]
Easier, faster, cleaner.
ps: by the way you have a bug in your << operator. [i][i] should be [i][j]
|
|
|
|
|
I am running a multiproject application and in one of the projects, there is a Process created using CreateProcess. This process uses an executable created in another project of this same application to perform certain tasks.
I am under the impression that if I add "DEBUG_PROCESS" as one of the options under CreateProcess, I should be able to debug into the Process (i.e. Go F11 and right into the actual file).
However, what I seem to get is a program that sort of hangs when it gets to WaitForSingleObject statement.
Any ideas of how to debug into a Process? What am I doing wrong?
thanks
|
|
|
|
|
Hello, the codegurus around the world.;)
I have the same problem to debug some project.
In this case, I wrote the following.
#ifndef _DEBUG
WaitForSingleObject (...);
#endif
This approach will not solve the basic problem, but
we can debug the different EXE created by CreateProcess.
So, in the debug mode, we can teminate the main exe process by debug menu,
otherwise, we will get some messy situation since we never call WaitForSingleObject.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
I am using MFC for a XP program, and have various controls on the dialog box.
When I add my .manifest file, all the controls are displayed as they should be (flat, hot tracking etc), but if I add the style "ES_PASSWORD" to an Edit box, I don't get the '*' character or the XP black circle, instead I get a small black rectangle.
Help.
Joe.
|
|
|
|