|
Check out what's being displayed on this phone:
http://www.cnn.com/2004/TECH/ptech/12/27/cell.phone.viruses.ap/index.html
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
interesting....does the mean that I can program a phone using c++?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
does the mean that I can program a phone using c++?
I'm not big into telephony, but it would not surprise me one bit, especially with the newer, more powerful computer phones.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
This program in g++ under liunux. then i made it to compile it under vc++(of course i have to change things slightly). the program is compiling without any error but it is not giving any output.
This code is compiled under VC++:
#include <iostream>
#include <set>
#include <queue>
#include <list>
using namespace std;
#include <stdio.h> // 2
struct Situation {
set<int> left, right;
bool torchLeft;
int minutesPassed;
list<string> description;
};
bool operator<(const Situation &a, const Situation &b)
{
return a.minutesPassed > b.minutesPassed;
}
int main()
{
const char *n[11] = { 0, "A", "B", 0, 0, "C", 0, 0, 0, 0, "D" };
priority_queue<Situation> q;
Situation s;
char d[256];
// initial situation: all persons and torch on the left
s.left.insert(1);
s.left.insert(2);
s.left.insert(5);
s.left.insert(10);
s.torchLeft = true;
s.minutesPassed = 0;
q.push(s);
while (!q.empty()) {
// q is sorted by minutesPassed increasing, get the top-most
// entry, which has the shortest minutesPassed of the queue
s = q.top();
q.pop();
// if all persons are on the right, this is a solution
if (s.left.empty()) {
cout << "solution found: " << s.minutesPassed <<
" minutes" << endl;
for (list<string>::iterator i = s.description.begin();
i != s.description.end(); ++i)
cout << " " << (*i).c_str << endl; // 1
cout << endl;
continue;
}
set<int> &src = s.torchLeft ? s.left : s.right;
// single person moving
for (set<int>::iterator i = src.begin(); i != src.end(); ++i) {
Situation t = s;
if (t.torchLeft) {
t.left.erase(*i);
t.right.insert(*i);
} else {
t.right.erase(*i);
t.left.insert(*i);
}
t.minutesPassed += *i;
if (t.minutesPassed >= 18)
continue;
_snprintf(d, sizeof(d), "%s moves %s (%d minutes, %d " // 2
"total)", n[*i], t.torchLeft ? "across" : "back",
*i, t.minutesPassed);
t.description.insert(t.description.end(), d);
t.torchLeft = !t.torchLeft;
q.push(t);
}
// two persons moving
{ // 3
for (set<int>::iterator i = src.begin(); i != src.end(); ++i)
for (set<int>::iterator j = i; j != src.end(); ++j) {
if (j == i)
continue;
Situation t = s;
if (t.torchLeft) {
t.left.erase(*i);
t.left.erase(*j);
t.right.insert(*i);
t.right.insert(*j);
} else {
t.right.erase(*i);
t.right.erase(*j);
t.left.insert(*i);
t.left.insert(*j);
}
t.minutesPassed += *i > *j ? *i : *j;
if (t.minutesPassed >= 18)
continue;
_snprintf(d, sizeof(d), "%s and %s move %s (%d " // 2
"minutes, %d total)", n[*i], n[*j],
t.torchLeft ? "across" : "back",
*i > *j ? *i : *j, t.minutesPassed);
t.description.insert(t.description.end(), d);
t.torchLeft = !t.torchLeft;
q.push(t);
}
}
}
return 0;
}
the required output should be like this:
solution found: 17 minutes
A and B move across (2 minutes, 2 total)
A moves back (1 minutes, 3 total)
C and D move across (10 minutes, 13 total)
B moves back (2 minutes, 15 total)
A and B move across (2 minutes, 17 total)
solution found: 17 minutes
A and B move across (2 minutes, 2 total)
B moves back (2 minutes, 4 total)
C and D move across (10 minutes, 14 total)
A moves back (1 minutes, 15 total)
A and B move across (2 minutes, 17 total)
can you please point out the error and re-paste the correct code(so that i can compare and understand better), i will be thankful to you.
|
|
|
|
|
compile under debug (which may actually be the default setting if you haven't changed it in VC), and use the step function.
It will serve you better to learn how to watch the program progress through stepping through your own code as you can find your mistakes in the future faster. Use the step to step through one line at a time. With a program this size, it should be very easy and very rapid to step through. You can inspect variables using the tools in the system as well so that you have a full detailed knowledge of how things are progressing.
As your programs get more complicated, and you can narrow down where an error occurs before you debug, you can set a "break" which will stop execution and let you step through from that point forward. You shouldn't need that yet as this program is small. Do familiarize with the tools at your disposal. Similar tools are available in most compilers, if you know "what to look for" rather than specific instruction, you can find the same capability.
Use the help, search the index for key words, "debug" "trace" "step". There is a lot of information to help you if you learn where to look and what is there to help you.
Jeff
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
|
I know that with the sizeof function I can determine how many bytes a type takes up e.g. char = 1 byte. However I want to parse C++ source code and then from the variables located in the parsed source code determine the byte size. I parse the variable type into a string but then sizeof determines the byte size of the string and not the actual variable type.
Does anybody know how I can do this? I.E. get the type of a variable from parsed code and then determine size.
I am the handsome one in the crowd.
|
|
|
|
|
if (token = "int") size = sizeof(int);
else if (token = "char") size = sizeof(char);
else if (token = "foo") size = sizeof(foo);
etc..
C/C++ does not have a way to turn input (your parsed source code) into executable code (an actual sizeof(...) operation) on the fly, so anything you do like this has to be done as a lookup table of some kind.
Software | Cleek
|
|
|
|
|
In order to determine the size of a variable in an arbitrary piece of C++ code, you must replicate a significant portion of the functionality in a compiler. This is a major task.
Given that you tried to determine the size of a type based on the sizeof the string containing the type name, I would guess you're fairly new to programming. First of all, the sizeof operator doesn't usually return anything meaningful with regards to the contents of a string, since strings are usually represented as a pointer. Usually you need to use a function or class method that returns the string length. Secondly, the length of the type name has nothing to do with size of the type itself. Here's a couple of examples:
class S {
char data[100000];
};
class ThisIsATypeWithAVeryLongNameAndLotsOfWords {
char data;
}; Both S and ThisIsATypeWithAVeryLongNameAndLotsOfWords are type names, but as you can see, the length of the name doesn't affect the size of the underlying type. S occupies 100000 characters, while ThisIsATypeWithAVeryLongNameAndLotsOfWords only uses one.
What are you trying to accomplish here?
Software Zen: delete this;
|
|
|
|
|
I have very strange problem. See this code:
I used this mfc class to connect to ftp
CFtpConnection *m_pFtpConnection;
CInternetSession m_Session(NULL, 1, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_DONT_CACHE);
m_Session.SetOption(INTERNET_OPTION_REQUEST_FLAGS, INTERNET_REQFLAG_CACHE_WRITE_DISABLED);
end the connection:
try {
m_pFtpConnection = m_Session.GetFtpConnection(strHostname, strLogin, strPassword, nPort, bPassive);
m_pFtpConnection->SetCurrentDirectory(strFrom);
here i want get name of the newest file on ftp:
CFtpFileFind finder(m_pFtpConnection);
BOOL bWorking = finder.FindFile((LPCTSTR)strFrom, INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RAW_DATA);
FILETIME ft1;
TimeStamp ts1(1971, 1, 1, 0, 0, 0);
TimeStamp ts2;
CString strGetFile;
while(bWorking) {
bWorking = finder.FindNextFile();
finder.GetLastWriteTime(&ft1);
TimeStamp ts2(ft1);
if(!finder.IsDots()) {
if(!finder.IsDirectory()) {
if(ts1
|
|
|
|
|
Hello Friends,
I have a progress bar with some data being displayed in it which is present on the StatusBar. My main problem is when ever I am resizing the window, the progress is not getting resized dynamically. I had used OnSize() member function, then also its not working. Please help me regarding this problem.
thanks in advance.
Neelesh K J Jain.
|
|
|
|
|
Hi!
Can anybody help me about how to hide toolbar and Menubar(File,Edit,View,Favourites,Tools,Help menu items) form Intenet Explorer leaving only the client area. Solution may be a visual c++ program reference or some registry settings.
|
|
|
|
|
Press the f11 hot key when ever u browse the ie
|
|
|
|
|
i am trying to do it in visual c++ so that nobody dare to access it. pressing F11 is a total joke.
|
|
|
|
|
Search for BHO on CP
Thanks
|
|
|
|
|
Search for BHO on CP
Thanks
|
|
|
|
|
hai !
i am facing a pbm in c++ . How can i prevent from inheritance of my class..
example:
class a
{
}
class b:public a
{
}
i want to prevent a from b not inherit like in java final keyword....
|
|
|
|
|
Switch to java
can't do it in C++
-prakash
|
|
|
|
|
can we check in base class constructor with this pointer which class is inveoked with this we can prevent from inheritance
sai
|
|
|
|
|
virtualkirankumar wrote:
can we check in base class constructor with this pointer which class is inveoked with this we can prevent from inheritance
sai
or make all members private. but i dont understand the your intention.
If the user cannot inherite ur class, then the user can certainly write a wrapper over ur class, which you cant prevent.
My suggestion,
be constructive on the class logic. if you are worried about ppl using ur class, just stick a copy right notice on the top.
-prakash
|
|
|
|
|
As Prakash says, there is no keyword for this. But there is a method for getting the same kind of encapsulation.
First you declare the interface for you class in a cpp file, then you declare an implementing class in a header file.
Here's a small example:
The header file dclares the interface Public, and a function that creates an instance:
<span style="color: green;">
<span style="color: blue;">#ifndef</span> _TESTER_H_
<span style="color: blue;">#define</span> _TESTER_H_
<br> <br>
<span style="color: green;">
<span style="color: blue;">class</span> Public
{
<span style="color: blue;">public</span>:
<span style="color: blue;">virtual int</span> GetX() = 0;
};
<br> <br>
<span style="color: green;">
Public * CreatePublic(<span style="color: blue;">int</span> x);
<br> <br>
<span style="color: blue;">#endif</span> // _TESTER_H_
The cpp file declares the implementing class Private:
<span style="color: green;">
<span style="color: blue;">#include</span> "tester.h"
<br> <br>
<span style="color: green;">
<span style="color: blue;">class</span> Private: <span style="color: blue;">public</span> Public
{
<span style="color: blue;">public</span>:
Private(<span style="color: blue;">int</span> x): m_x(x)
{
}
<br> <br>
<span style="color: blue;">int</span> GetX()
{
return m_x;
}
<br> <br>
<span style="color: blue;">private</span>:
<span style="color: blue;">int</span> m_x;
};
<br> <br>
Public * CreatePublic(<span style="color: blue;">int</span> x)
{
return new Private(x);
}
Here's how to use it:
<span style="color: blue;">#include</span> "tester.h"
<br> <br>
<span style="color: blue;">int</span> main()
{
<span style="color: green;">
<span style="color: green;">
<br> <br>
Public * pPub = CreatePublic(42);
<span style="color: blue;">delete</span> pPub;
<br> <br>
<span style="color: blue;">return</span> 0;
}
The funny thing is, that while the Java keyword final optimizes the code by removing the need for a vtable, this C++ technique adds an overlay by creating a vtable.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
|
Hi!
I'm using the great COptionTree (http://www.codeproject.com/treectrl/coptiontree.asp)
So far no problems, but then I tried to combine it with a "Sidebanner" (http://www.kinkycode.com/?section=cppdev&sub=kcsidebannerwnd)....in order to have a small image on top of my dialog..
But now i have the problem, that the optiontree "moves under" the bannerimage...
Now here my question..how can i set that the y-position of the optiontree "moves" 40 pixels downwards..?
I think the OnSize function is responsable for my problem..so here the code which i have in my dialog..:
Isn't it possible to just move the OptionTree 40 pixels downwards??
Perhaps somebody can tell me the code, i have to add
void CPrefsDlg::OnSize(UINT nType, int cx, int cy)
{
// Resize the control
if ((cx > 0) && (cy > 0))
{
if (::IsWindow(m_otTree.GetSafeHwnd()))
{
m_otTree.MoveWindow(0, 0, cx, cy);
}
}
CPropertyPage::OnSize(nType, cx, cy);
}code>
mfg
|
|
|
|
|
if you post this question at http://www.codeproject.com/treectrl/coptiontree.asp[^] forum, maybe the author would be in a better position to help you out.
-prakash
|
|
|
|
|
|