I was wondering if someone could look at my code and tell me why when i try to get the average of the array it wont give me the average. It compiles, the only problem is the sum and average are the same. here is my code
// LanusArrays.cpp : Defines the entry point for the console application.
// Corey Lanus
// Test 2 Part 2
// Lanus Arrays
// Does a lot of things dealing with arrays.
// October 16, 2006
using namespace std;
const int ARRAY_SIZE = 20;
When you get all this working the way you want, be sure and check out some of the STL algorithms. They can do a lot of this for you. For educational purposes, it's always nice to do everything yourself (I started this way and am better for it), but just know that standard functions and classes do exist for some things.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
I'm doing a project where I've got 4 classes for a database. I've got CRecordSet derived classes for each of the tables I'm interacting with.
Here's an example of two of the tables:
* Part Structure. Holds the information associated with
* a part in the database's part table (for single part).
typedef CArray<part, part> MyPartArray;
class CPartsTable : public CRecordSet
// MFC Junk here
BOOL AddNew(part& p); // Adds a new part to the table
BOOL Edit(part p); // Edits an existing part
BOOL Delete(part p); // Removes a part from the table
BOOL GetList(MyPartArray& list); // Returns a list of part structs
* Board structure. Holds the information associated with
* a single board.
typedef CArray<board, board> MyBoardArray;
class CBoardTable : public CRecordSet
// MFC Junk here
BOOL AddNew(board& p);
BOOL Edit(board p);
BOOL Delete(board p);
BOOL GetList(MyBoardArray& list);
I was thinking that it would make my life much easier if I could wrap them in a common interface like so:
You could get the inheritance to work by making the interface a template, i.e.
virtual BOOL AddNew(T&)=0;
virtual BOOL Edit(T)=0;
virtual BOOL Delete(T)=0;
virtual BOOL GetList(CArray<T,T>&)=0;
class CPartsTable : public CRecordSet, ICommonTable<part>
class CBoardTable : public CRecordSet, ICommonTable<board>
This would help if you were writing a lot of generic functions that operated on the tables without needing to know the details (for instance an algorithm that deleted every second entry could be written as a template function and would work on both part and board tables). However without knowing why you think the common interface would make your life easier then it is hard to know whether this would help or not.
I have been developing C++ code for many years now, but I am relatively new to MFC. I am going through the book "Programming Windows 95 with MFC" (First Edition) by Jeff Prosise. I have carefully gone through the first seven characters of the book. I also went through all the examples and ran them on my computer with no problems. I have also written three toy MFC applications.
When I get to chapter 8 (which deals with SDI), I cannot get the example to work. I feel that MFC programs written using the SDI model are hard to understand and hard to debug. I do not see the SDI model as a big time saver for the developer. Is it really that good? By the way, if somebody has a small (say under 100 lines) MFC SDI program that they could send me, I would really appreciate it.
The reason I am learning MFC is that I want to write a 1st class Retirement Calculator. Should such a program be written as a SDI application? I am thinking that it should not.
The book you've got is really good for learning MFC.
The question I have is: what version of visual studio are you using to run the examples? I found it easy to compile the examples with VC++ 6.0. I think that the newer versions of VC++ will work but you might get some problems.
As far as the need for SDI and MDI applications: you can usually get by just using dialog based apps. However, the SDI apps provide a better design framework. This is especially true if you want to distribute your presentation code from you data handling code. The SDI framework also makes it easy to save your application's data.
One thing that might help you is to try deriving the View class from CFormView. This has the effect of combining the SDI Document/View framework with the ease of Dialog programming. (The App wizard allows you to change the View base class in the last step.)
You added an extra semicolon, but the statement does make sense. It should be:
weekly wages = 12.75*40 + ( (40>40) ? (12.75*40/2) : 0 );
Now, 12.75*40 = 510 and 40 > 40 is false so we have
weekly wages = 510 + 0
weekly wages = 510
I am using API RegEnumValue() to retrieve the regkey's values. However, for DWORD and BINARY datatype it returns some garbage or junk characters in buffer(for the values which has above datatypes).. do I need to typecast this returned data to make it readable in eng ??? if yes how shud I do that, any pointers ?
Thanks in advance.
The Registry Key Value Type is 'REG_DWORD' and 'REG_BINARY'.
You can create any new key in registry and then create new key values for it which has datatype as above(Selecting 'DWORD Value' and 'BINARY Value') and plz have a look at datavalue to see how data looks like.. For 'REG_SZ' values I am getting data in buffer properly.
Sample Code : (Assume regkey handle and open proc is passing and I am able to access it thru another APIs)
// Enumerate the key values.
for (i=0, retCode=ERROR_SUCCESS; i<dwvalues;>
retCode = RegEnumValue(
hkScanKey, // Handle to an open registry key
i, // The index of the value to be retrieved
pszRegValueName, // Pointer to a buffer that receives the name of the value
&dwRegValNameLen, // Size of the buffer pointed to by the 'pszRegValueName'
NULL, // Reserved
&dwRegValType, // Type of data
(LPBYTE)pszRegValData, // Data for the value
&dwRegValLen); // Size of Data
so whenever it finds any value with datatype 'REG_DWORD' or 'REG_BINARY' , the buffer 'pszRegValData' has some garbage value or unreadble val...
Last Visit: 31-Dec-99 19:00 Last Update: 6-Dec-23 0:55