|
i have two WXP installations in two different partitions: i have the need to edit the registry .dat file in the inactive partition. Manually it could be accomplished by using the "load hive" function.
Is there any class to achieve that, programmatically? It seems that all the existing classes are aimed to editing the currently open registry.
Thanks in advances!
|
|
|
|
|
Hi, all. I need some help with a program. I'm not asking you to do the entire thing for me but I won't complain Here is my assignment:
Write a program that uses a stack to return to the user the OCTAL, HEXADECIMAL and BINARY equivalents of a DECIMAL integer input by the user.
EXAMPLE: User_Value 58 base 10 returns 3A base 16, 72 base 8 and 111010 base 2
You need to hand in an algorithm (PSEUDOCODE only) along with the source code and output.
You need to : initialize the stack
check to see if it is full or empty
destroy the stack
PUSH and POP
Can you get me started? I'm sure it's like real easy, in fact I have a nice c program to do the coversion, but I just can't seem to figure how to implement this using a stack. Please, any help would be great. I didn't find this forum till yesterday and my project is due Thursday. Thank you for anything you can provide.
|
|
|
|
|
This is a pseudo-C example of how one would convert a 10-base number to a different base.
It assumes a String class that provides the = and + operators and a Stack class that implements
the push and pop functions.
String BaseConversion(int Number, int Base)
{
int digit;
Stack stack = new Stack();
while (Number >= Base)
{
stack.push(Number % base);
Number = Number/Base;
}
digit = Number
String str = new String("" + digit)
while (stack.NotEmpty())
str = str+stack.pop()
return str;
}
|
|
|
|
|
Thank you so much for your reply! However, I do need just a little more explanation. I know how to create a stack class, but I don't recall string classes; i'm going to go through my texts or search the net for clarification. I do appreciate you including your remarks, and I have some questions. Would I form two versions of this function, one for binary and one for hex, and they would both be seperate calls? Also, my book example showed something like this: If you add 6+3, you push on 6, then 3, and then you pop them off and store them in variables, such as op1 and op2, then perform the addition. I believe the instructor is utilizing a stack for the purpose of something long such as 6+(4*3)/2, should the case ever be necessary. I have not created a stack class before, but one example I was shown uses a case situation, like should you press "+" then it would perform addition, and so on. Thanks again for your time, and look forward to your comments.
|
|
|
|
|
Well, when I first read your post my understanding was that you needed a pseudo-code version of the program. Hence my post...
So, issue number 1: the String class; Now, I'm not sure what language you're planning to use to implement this program so that makes your question a bit hard to answer without further clarification. In classical C++, if I recall correctly, there is the std namespace that I provides a string class (std::string) which should meet the requirement of the code snippet that I have shown above. If you are using a different version of C++ such as the Managed Extentions for C++ (which is really what I think this group should be about, given the "CLI" suffix) there is also a managed String class which is available in the System namespace.
Issue number 2: How to use the function. Basically all you would have to do in your program is call the Convert function as such (example in classical ANSI C++)
<code>
std::string strBase2;
std::string strBase8;
std::string strBase16;
strBase2 = BaseConversion(no, 2);
printf("%d [Base 10] = %s [base 2]", no, strBase2);
strBase8 = BaseConversion(no, 8);
printf("%d [Base 10] = %s [base 8]", no, strBase2);
strBase16 = BaseConversion(no, 16);
printf("%d [Base 10] = %s [base 16]", no, strBase2);
</code>
but I really think that you need to first try to understand more basic concepts in order to be able to take advantage of these posts. Try googling for some tutorials on C++ first (look for basic stuff such as functions etc.), then look for some tutorials on data structures (you need to understand the stack and queue concepts at least).
P.S. the std namespace in C++ should also provide a stack class
-- modified at 22:40 Thursday 10th November, 2005
|
|
|
|
|
how can I replace the array's and do something equivalent. I can't figure out how do change it...... i hav a mental block....
<code></code>
#define MAXVAL 10000000
char primes[MAXVAL];
int main ()
{
// initiallize the primes array
for (/*long*/ int i=0; i<MAXVAL; i++)
{
primes[i] = 0;
}
// Set primes[i] equal to 1 for all not prime numbers
for (/*long*/ int i=2; i</*sqrt((float)*/MAXVAL/*)*/; i++)
{
if (primes[i] == 0)
{
for (/*long*/ int notprime = 2*i; notprime < MAXVAL; notprime+=i)
{
primes[notprime] = 1;
}
}
}
long int test = 0;
// read input one at a time
//while(test>=4)
//{
cout<<"Please input a even integer greater than or equal to 4 : ";
while (cin >> test /*&& test >=4*/)
{
//if(test>=4)
//{
// loop through every possible odd sum
for(long int i=2; i<test/1; i+=1)
{
// if this is a valid prime sum, pring it and break to get the new input
if (primes[i] == 0 && primes[test-i] == 0)
{
int n = test;
int p = i;
int q = test - i;
cout << n << " = " << p << " + " << q << endl;
cout <<"The value of p is "<<p<<endl;
cout <<"The value of q is "<<q<<endl;
break;
}
//else
//cout<<"Invalid input..."<<endl;
//break;
}
//}
}
//}
pause();
return EXIT_SUCCESS;
}
<pre></pre>
|
|
|
|
|
Are you allowed to use the STL ? I'd do this by building a set of prime numbers and checking to see if the number I was given was in it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
my first issue is that i have no idea what is actually happining to cause the leak. To try and find the leak i have commented out most of the code leaving just the basics. First, i create a linked list, then i delete it. thats all thats left of the code. all of the objects of the linked list are deleted and all the nodes are deleted. but something else remains. when i run it, there is a 44 byte memory space still open. my objects are 33 byte (i think). i tried to follow the code as it called new, but was unable to determine who might be calling new and not freeing up.
there are other leaks in the program as well, but i feel that they all resemble this one.
any help or explaination would be greatly appreciated.
int main()<br />
{<br />
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);<br />
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);<br />
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);<br />
<br />
CatagoryPricingLinkedList* cll = new CatagoryPricingLinkedList;<br />
CatagoryPricing aCat;<br />
aCat.LoadCat(cll);<br />
<br />
delete cll;<br />
return 0;<br />
}<br />
<br />
<br />
<br />
class CatagoryPricingNode<br />
{<br />
public:<br />
CatagoryPricingNode(){}<br />
virtual ~CatagoryPricingNode(){}<br />
<br />
virtual CatagoryPricingNode* InsertCatagoryPricing(CatagoryPricing* aCatagoryPricing)= 0;<br />
virtual void ShowMe()=0;<br />
virtual void Show()=0;<br />
virtual CatagoryPricing* GetCatagoryPricing()=0;<br />
virtual CatagoryPricingNode* GetThisNext()=0;<br />
<br />
<br />
private:<br />
<br />
};<br />
<br />
class InternalCatagoryPricingNode : public CatagoryPricingNode<br />
{<br />
public:<br />
InternalCatagoryPricingNode(CatagoryPricingNode* next, CatagoryPricing* aCatagoryPricing)<br />
{ <br />
m_next = next;<br />
m_CatagoryPricing = aCatagoryPricing;<br />
}<br />
~InternalCatagoryPricingNode(){delete m_CatagoryPricing;<br />
delete m_next;}<br />
<br />
CatagoryPricingNode* InsertCatagoryPricing(CatagoryPricing* aCatagoryPricing)<br />
{<br />
CatagoryPricingNode* aNode = new InternalCatagoryPricingNode(this, aCatagoryPricing);<br />
return aNode;<br />
}<br />
<br />
private:<br />
CatagoryPricingNode* m_next;<br />
CatagoryPricing* m_CatagoryPricing;<br />
};<br />
<br />
class TailCatagoryPricingNode : public CatagoryPricingNode<br />
{<br />
public:<br />
TailCatagoryPricingNode(){}<br />
~TailCatagoryPricingNode(){}<br />
CatagoryPricingNode* InsertCatagoryPricing(CatagoryPricing* aCatagoryPricing)<br />
{<br />
CatagoryPricingNode* newnode = new InternalCatagoryPricingNode(this, aCatagoryPricing);<br />
return newnode;<br />
}<br />
<br />
private:<br />
};<br />
<br />
<br />
class HeadCatagoryPricingNode : public CatagoryPricingNode<br />
{<br />
public:<br />
HeadCatagoryPricingNode(){m_next = new TailCatagoryPricingNode();}<br />
~HeadCatagoryPricingNode(){delete m_next;}<br />
<br />
CatagoryPricingNode* InsertCatagoryPricing(CatagoryPricing* aCatagoryPricing)<br />
{<br />
m_next = m_next->InsertCatagoryPricing(aCatagoryPricing);<br />
return this;<br />
}<br />
<br />
private:<br />
CatagoryPricingNode* m_next;<br />
<br />
};<br />
<br />
class CatagoryPricingLinkedList <br />
{<br />
public:<br />
CatagoryPricingLinkedList()<br />
{<br />
m_head = new HeadCatagoryPricingNode;<br />
pCurrentPtr = m_head;<br />
m_tail = m_head->GetThisNext();<br />
<br />
}<br />
<br />
~CatagoryPricingLinkedList()<br />
{<br />
delete m_head;<br />
};<br />
<br />
void Insert(CatagoryPricing* aCatagoryPricing)<br />
{<br />
m_head->InsertCatagoryPricing(aCatagoryPricing);<br />
}<br />
<br />
private:<br />
CatagoryPricingNode * m_head;<br />
CatagoryPricingNode * m_tail;<br />
CatagoryPricingNode * pCurrentPtr;<br />
CatagoryPricingNode * temp;<br />
};<br />
<br />
class CatagoryPricing<br />
{<br />
public:<br />
<br />
CatagoryPricing(){ <br />
pricelvl1=0;<br />
pricelvl2=0;<br />
pricelvl3=0;<br />
pricelvl4=0;<br />
pricelvl5=0;<br />
costlvl1=0;<br />
costlvl2=0;<br />
costlvl3=0;<br />
costlvl4=0;<br />
costlvl5=0;<br />
totalnumbertoorder=0;<br />
totalinstock = 0;<br />
<br />
};<br />
~CatagoryPricing(){};<br />
<br />
CatagoryPricingLinkedList* LoadCat(CatagoryPricingLinkedList* cll);<br />
private:<br />
<br />
};<br />
<br />
CatagoryPricingLinkedList* CatagoryPricing::LoadCat(CatagoryPricingLinkedList* cll)<br />
{<br />
<br />
CatagoryPricing* aCatagory; <br />
<br />
do <br />
{<br />
aCatagory = new CatagoryPricing;<br />
<br />
<br />
cll->Insert(aCatagory);<br />
<br />
inf.peek();<br />
}while(inf.good());
<br />
inf.close();<br />
return cll;<br />
}<br />
|
|
|
|
|
I guess the first question is, why are you writing a linked list class ? If it's for homework, fair enough. Otherwise, you should use the one that C++ provides.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
to be honest i hate the one C++ provides. i don't like its functionality. but, since all the objects are deleted this still doesn't point to why there is a leak.
|
|
|
|
|
nineofhearts wrote: to be honest i hate the one C++ provides. i don't like its functionality.
Really ? Why ? Surely your linked list does not provide iterators to allow for use with other containers and the algorithm library that comes with c++ ?
I'm looking at your problem
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sorry, I can't run this code as it stands, because the order of classes is wrong for it to compile.
However, I notice when you call new, you don't put the (). I'm not sure if this makes a difference ? Also, you seem to have a few member variable pointers that don't get initialised to NULL in a constructor, could this be a problem ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
sorry about the code being in the wrong order. didn't consider that when i was cutting and pasting. I tried adding the new() but that didn't help ( and i have never seen it that way in my text) also, initilized the remaining variables with NULL and no change.
as for why i like using my linked list (or more specifically don't like the one C++ provides) ease. mine is simpler for me to use for the little jobs its required to do.
|
|
|
|
|
nineofhearts wrote: mine is simpler for me to use for the little jobs its required to do.
Perhaps. But if you learned to use the full powered one, you'd find it easy to use all the time
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
One of the reasons to prefer the standard library containers is because when we roll our own we're likely to run into the problems you describe!
But if you don't like the standard library why not find another library and use that?
Kevin
|
|
|
|
|
I finally got this to compile and it didn't leak.
PS. I hate STL too.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
-- modified at 2:20 Saturday 12th November, 2005
|
|
|
|
|
I am looking to learn how to implement non-simple callbacks to managed code unmanged C++. I can get a simple non-parametered callback examples working. But, I want to pass an object along for the ride through unamanged and have it show up as a parameter to the managed callback - perhaps the object will be in unmanaged code for along time before the callback - almost certainly during garbage collection. I would appreciate any help I can get - I know others have gocne through this and solved it.
Here is the code I am trying to use...
using namespace System;
using namespace System::Runtime::InteropServices;
#pragma unmanaged
// declare the unmanaged function prototype
typedef void (*MY_CALLBACK)(void *);
// Declaration of the unmanaged class
class CMyUnmanaged
{
public:
CMyUnmanaged() { }
// The unmanaged class method where the
// function pointer will be invoked.
void DoCallback( MY_CALLBACK myCallback, void *myParam )
{
// invoke the method
myCallback( myParam );
}
};
#pragma managed
namespace CallbackTest
{
// Protoype of the Delegate the matches the function pointer
// declaration the unmanaged code expects to receive.
public __delegate void CallbackDelegate( Object *obj );
// This is for marchalling the function pointer.
[StructLayoutAttribute( LayoutKind::Sequential, CharSet = CharSet::Unicode) ]
public __gc struct MyDelegate_Struc
{
[MarshalAsAttribute(UnmanagedType::FunctionPtr)]
CallbackDelegate* _Delegate;
};
// This is an attempt to marshall the object data we want to
// "pass through" unamanged code.
[StructLayoutAttribute( LayoutKind::Sequential, CharSet = CharSet::Unicode) ]
public __gc struct MyParam_Struc
{
[MarshalAsAttribute(UnmanagedType::Struct)]
Object* _Param;
};
// Managed class wrapper to be used for the callbacks.
public __gc class CMyManaged
{
private:
CMyUnmanaged __nogc *pUnManaged;
public:
CMyManaged()
{
// unmanaged class instance
pUnManaged = new CMyUnmanaged();
}
~CMyManaged()
{
// delete it because the GC won't
delete pUnManaged;
}
// here is where we try to get unmanaged code to invoke the callback.
void DoCallback( CallbackDelegate *pDelegate, Object * pObject )
{
// pin the object pointers
CallbackDelegate __pin *_cb = pDelegate;
Object __pin *_ob = pObject;
// these are the unmanaged types we need to pass
// to the unmanaged code that will be making the
// callback.
MY_CALLBACK fn;
void* ob;
// use interop to create the pointers we need
// from the objects we are passed.
// Create the Function Pointer
MyDelegate_Struc *s = new MyDelegate_Struc();
s->_Delegate = _cb;
Marshal::StructureToPtr( s, &fn, false );
// Attempt to create a void * pointer
MyParam_Struc *u = new MyParam_Struc();
u->_Param = _ob;
Marshal::StructureToPtr( u, &ob, false );
// make the method call (which fails...)
pUnManaged->DoCallback( fn, ob );
}
};
}
//
// and lastly the C# code that tries to run it all...
//
using System;
using CallbackTest;
namespace MyTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string _test = "Hello World";
CMyManaged cmm = new CMyManaged();
cmm.DoCallback( new CallbackDelegate( ThisCallback ), _test );
}
static void ThisCallback( Object obj )
{
Console.WriteLine( obj.ToString() );
}
};
}
You know neither the day nor the hour.
|
|
|
|
|
I want write a console program like this:
...
CMD> aaa <-- "aaa" is typed by user , without pressing [enter]
System : It is a msg <-- the system print msg for some event.
CMD> aaa <-- what i would like to ask is this :
"aaa" is still here and can be edited by user.
This should be a sigle-threaded, portable program.
the flow of this program is :
wait for any event or stdin input -> handle event -> wait event again ->...
I have no idea how to get user input without [ENTER] and print as editable text.
I have try conio , but it seems not portable...
Hope I will be helped. Thanks!
|
|
|
|
|
According to MSDN, getch is not standard C++, but _getch is ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi all,
I developed windows form application using VC++.NET.
I have a check box that i need to know its status from another file. I can access it from the class file (using its name or this pointer) but i can't access it from another file within the project.
How can i do it?
I tried using the class namespace but no good.
Please help.
10'x
|
|
|
|
|
Your check box should be private, you shouldn't be able to access it outside the class. It sounds like this is so. You should expose a public method to get the state of the checkbox.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I need help using fstream...
i need to read a text file that has multiple lines, each line has the syntax:
'fname lname 01 02 03 04 05 06 07 08 08 10'
that is a first name space last name space and 10 test scores (separated by spaces). I then have to move all the data from one file to another except i have to add the average of the 10 scores to the end of each line...
I can read the full text and display as it is from one file to the other. The problem is i can't read just the numbers in order to get the average...here's the code i have so far...
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
using namespace std;
#define INPUTFILE "HW660-In.txt"
#define OUTPUTFILE "HW660-Out.txt"
void rwFiles(ifstream& inSource, ofstream& outSource);
bool goOn();
void main()
{
dispHeader();
do
{
ifstream inStudentRecord;
ofstream outStudentRecord;
inStudentRecord.open(INPUTFILE);
if (inStudentRecord.fail())
{
cout<<"Opening input file failed.\n";
exit(1);
};
outStudentRecord.open(OUTPUTFILE);
if (outStudentRecord.fail())
{
cout<<"Opening output file failed.\n";
exit(1);
};
rwFiles(inStudentRecord, outStudentRecord);
inStudentRecord.close();
outStudentRecord.close();
}while(goOn());
}
void dispHeader()
{
void rwFiles(ifstream& inSource, ofstream& outSource)
{
char next;
int iGrade = 0, oGrade = 0;
inSource.get(next);
while (!inSource.eof())
{
if(next == '\n')
{
cout<<" The End"; //this adds "The End" at the end of every line.
};
cout<<next;
outsource<<next;
="" insource.get(next);
="" };=""
}
bool="" goon()
{
="" char="" calcmore="Y" ;
="" bool="" goon="true;
" cout<<"would="" you="" like="" to="" continue?="" (y="" n)="" ";
="" cin="">>calcMore;
switch (calcMore)
{
case 'Y': case 'y': ;break;
case 'N': case 'n': default: goOn = false;
}
return goOn;
}
So basically all my code does is reads exactly what is in the input file and displays it to the screen as well as copies it to the output file.
noob in need of help...
|
|
|
|
|
If you know the format of the file, you can use the << operator to read the file into the appropriate variable types, which in this case is two strings, and 10 numeric types. As it stands, you're reading a char at a time. The real alternative to what I've suggested is to use getline and then munch the string to extract the data by looking for spaces and using substr and atoi to convert to ints.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
In those situation stringstream can be cool!
http://www.cplusplus.com/ref/iostream/stringstream/[^]
Here is the code to read one line in your file and to compute the average score.
std::ifstream ifs("FileName", std::ios::in);
char buffer[255];
ifs.getline(buffer, 255);
std::istringstream iss(buffer);
char n1[255];
char n2[255];
double grade, mean=0.0;
int nGrade = 0;
iss >> n1 >> n2;
for(; iss >> grade; ++nGrade) mean += grade;
mean /= nGrade;
ifs.close();
// end
Now figure a way to do this for the whole file
Eric
Premature optimization is the root of all evil
|
|
|
|
|
qfegd wrote: In those situation stringstream can be cool!
and (IMHO) utterly superfluous...
there is already and input stream open in the form of the input file stream
why read a line convert it to another input stream and then use operator>> on that stream
as the input text file is rigorously defined why not use >> directly on the input file stream?
operator>> is overloaded for the inbuilt types & defaults
to consuming white space and newlines (thanks Bjarne)
thus...
char n1[255];<br />
char n2[255];<br />
double total, mean, grade;<br />
int count = 10;
<br />
ifstream in_file(IN_NAME);
<br />
while(!in_file.eof()) {<br />
in_file >> n1 >> n2;<br />
total = 0.0;<br />
for(int i = 0, i < count, ++i) {<br />
in_file >> grade;<br />
total += grade;<br />
}<br />
mean = total / count;<br />
}
i will leave writing to the output file for you (it can all be fitted into the above loop in 3 lines)
if your input file might be dirty you could add
in_file.ignore(255,'\n');
to ignore upto 255 characters at the end of the line and any new line.
hope this helps?
|
|
|
|