Maritimo 15 Junior Poster in Training

May be, may be not :-)

Maritimo 15 Junior Poster in Training

See http://www.parashift.com/c++-faq/serialization.html
There, it is defined as:
Serialization lets you take an object or group of objects, put them on a disk or send them through a wire or wireless transport mechanism, then later, perhaps on another computer, reverse the process: resurrect the original object(s). The basic mechanisms are to flatten object(s) into a one-dimensional stream of bits, and to turn that stream of bits back into the original object(s).

Maritimo 15 Junior Poster in Training

I recomend you to use the function int toupper( int ch ) defined in header <cctype>

cambalinho commented: thanks +3
Maritimo 15 Junior Poster in Training

Consider you have a counter (c) that goes from 1 to 5.
The number of stars you what to print is s = 6-c.
In this way,
when c values 1 s values 5,
when c values 2 s values 4,
when c values 3 s values 3,
and so on.
That's all you need.

Maritimo 15 Junior Poster in Training

A for that do something 10 times can be written like this:

for(int i=1; i<=10; ++i)
{
   //...
}
Maritimo 15 Junior Poster in Training

You asked for an example!

Consider you have the classes Widget and SpecialWidget using simply inheritance like:

class Widget
{
   /*...*/
};

and

class SpecialWidget: public Widget
{
   /*...*/
};

Suppose that you need to count the number of objects that exist of class SpecialWidget at some point in your program.

Consider you have the following counter.h file (It is another problem to explain why it is written like this):

template<typename T>
class Counter
{
public:
  Counter() {++count;}
  ~Counter() {--count;}

  static size_t howMany() {return count;}

private:
  static size_t count;
};

template<typename T>
size_t Counter<T>::count = 0;

Well, to count the numbers of objects created of class SpecialWidget you only need to include counter.h into your widget.h file and modify your code in the following way:

class SpecialWidget: public Widget, private Counter<SpecialWidget>
{
   /*...*/
};

When you want to know the number of objects of SpecialWidget that exist at some point, at that point you just write:

int numberOfSpecialWidgetObjects = Counter<SpecialWidget>::howMany();

You can do exactly the same for any other class you need to count the number of objects:

class Derived : public Base, private Counter<Derived>
{
   /*...*/
};

and know the number of objects that exist at some point of Derived class with:

int numberOfDerivedObjects = Counter<Derived>::howMany();

Doing this without Multiple Inheritance is possible but not as elegant as it is with Multiple Inheritance.

Note: I didn't test the written code, so probably there are some …

Maritimo 15 Junior Poster in Training

The disadvantage of multiple inheritance is that for using it you need to know more than for not using it. However, if you know how to use it, it is a fantastic tool.

In other words, knowing a little of multiple inheritance, you can make a mess; knowing a lot, you can make very powerful things.

One important thing to take into account is that for doing any software you don't need Multiple Inheritance; in the same way you don't need inheritance at all; even you don't need data abstraction; nor the structures nor classes; and so on. At the end probably you only need a basic assembler. Remember that the humans went to the moon without neither computers nor calculators. In this way of think, you can not learn how to use Multiple Inheritance at all and probably nothing will happen while you don't try to use it. On the contrary, you can learn it very well and you will enjoy constructing interesting software.

There are programming languages that were constructed with the idea that Multiple Inheritance is dangerous (or difficult to learn) and have suppressed it. I think that all the languages are dangerous and difficult to learn on some degree; so probably, with the idea of those people, the most secure thing to do should be to restrict the use of languages to only very clever people.

C++ has included Multiple Inheritance with a very powerful concept, if you don't use it, you don't pay for it. …

Maritimo 15 Junior Poster in Training

Yes, it is perfectly possible to solve that problem in C++.

Maritimo 15 Junior Poster in Training

Try to use std::sort with std:list ;-)
timnased didn't said this was a homework, he just said he is making a phonebook program.

Maritimo 15 Junior Poster in Training

This link Stackoverflow can give you more information.

Maritimo 15 Junior Poster in Training

Replace strVec.push_back(getline(about)); with strVec.push_back(getline(infile));
Then show the vector strVec
Then sort the vector strVec
Finally show again the vector strVec

Maritimo 15 Junior Poster in Training

I think that rubberman has been a little exagerated because this is neither for a PhD nor even Master but he is right in that this is very difficult for a beginner.

You must learn about WEB servers and how to create utilities there. Also you need to learn about HTML and probably PHP to make a program that interact with pages on the internet.

Maritimo 15 Junior Poster in Training

The memory is measured in bytes.
1k bytes are 1024 bytes (not 1000 bytes). This is because the memory space is expresed in powers of two:

2^0=1
2^1=2
2^2=4
2^3=8
2^4=16
2^5=32
2^6=64
2^7=128
2^8=256
2^9=512
2^10=1024 <--- This is why 1k of memory has 1024 bytes.
2^11=2048
2^12=4096 <--- In your problem, one page of memory is 4k with 4096 bytes.

1kB = 1024 bytes
1MB = 1k x 1k memory = 1024x1024 = 1048576 bytes.
1GB 0 1M x 1k = 1k x 1k x 1k = 1024x1024x1024 = 1073741824 bytes

In the rest (of your live):
"k" means 1024
"M" means 1024 x 1024 = 1048576
"G" means 1024 x 1024 x 1024 = 1073741824

4kB = 4x1024 = 4096 bytes is one page of memory.

2^32 has 4294967296 bytes is your total space for your table.

2^32/1024 = 4194304 k bytes = 4194304x1024.
2^32/1024/1024 = 4096 M bytes = 4096x1024x1024.
2^32/1024/1024/1024 = 4GB = 4 x 1024 x 1024 x 1024.

That is: you have 4GB of total space memory. (The question is wrong because it says 4MB and must say 4GB).

2^32/1024/4 = 2^32/4096 = 1048576 pages of memory.

2^20 = 1048576. That is, you have 2^20 pages of memory.

2^20 = 1048576 = 1024x1024. That is you have 1024 k pages of memory.

You have 1M pages of memory and each page has 4k …

Maritimo 15 Junior Poster in Training

Try to use std::sort.

Maritimo 15 Junior Poster in Training

data_search is an integer. But is current->ID also an integer?
It seems that current->ID is a string. Probably you can use std::stoi(current->ID) to solve the problem.

Maritimo 15 Junior Poster in Training

What is your question?

Maritimo 15 Junior Poster in Training

Daniweb is not a homework service. Please provide evidence that you've attempted a solution on your own, as per our rules.

Maritimo 15 Junior Poster in Training

Daniweb is not a homework service. Please provide evidence that you've attempted a solution on your own.

Maritimo 15 Junior Poster in Training

What is your question?

Maritimo 15 Junior Poster in Training

See also what we said in "C or C++" discussion about learning C before C++.

Maritimo 15 Junior Poster in Training

On line 18, change get_values(*r, *v); with get_values(&resistor, &volts);

Also you can change line 39 from scanf("%f", &*r); to scanf("%f", r);
and line 43 from scanf("%f", &*v); to scanf("%f", v); but these are not stricly necessary.

Maritimo 15 Junior Poster in Training

Sorry but I can't tell you a book like that.

Also, is there an advantage to learning C before you learn C++?

No, there isn't. As a matter of fact, it is not recomended at all. Learn C++ directly. Knowing Python you have an advantage but resist the tentation to learn C++ "thinking" in Python or any other language. Translating every thing you learn in C++ to Python will make if harder.

Maritimo 15 Junior Poster in Training

We don't do homework.

Maritimo 15 Junior Poster in Training

Realy nice. I think that the final answer to the very initial question could be:

To achieve fast operations of STL libraries during development, you can compile different parts of your code with different optimization flags: -Og for that sections that require debugging and -O3 for that sections you are sure are correct (queue in this case). Doing this, in general make sure that the information transmitted between those parts are only fundamental types (bool, char, int, double, ...) and/or POD ("Plain Old Data"). You can be assisted to know if some data is POD with the predicate is_pod from <type_traits>.

If you need more than this with the STL library, you can follow the advice given by vijayan121 from gcc.gnu.org.

Maritimo 15 Junior Poster in Training

Do you want that someone make your homework?

Maritimo 15 Junior Poster in Training

map from std C++ lib.
Look at google for others.

Maritimo 15 Junior Poster in Training

Dear Mike, your answer is tricky. You said a lot of things that are totally true but it is not what I am proposing.

Assuming a situation where you have a function void foo(deque<int>&) that you compile for release...

Obviously you can not create an optimized version of a function like foo(deque<int>&) because that implies you are sending a reference of a deque --that change with the optimization flags--. That is the trick, to have some parts of the code with deque optimized and others with deque not optimized; and worst send references from one to the other. What you must do is to create a function foo(int) that internally "saves" the int into a deque.

In agreement with the problem set originally, what it is intended to be "saved" into the deque are floats:

#ifndef DEBUG
        // deque too slow
        std::deque<float> inFIFO;
        std::deque<float> outFIFO;
#else
        float* inFIFO;
        float* outFIFO;
#endif

So, it is totally possible to create a library compiled with -O3 that push and pull floats using internally a deque. The interface of this queue library will only transmit floats that do not change with the optimization flags.

I had suggested to create a library to store void* only as a general alternative to a queue<foo>, that as you said is not a perfect solution but is faster that the not optimized version.

But this is not the case here, the original problem is to create a queue for floats. Sorry that I went …

Maritimo 15 Junior Poster in Training

D is something like to try to create a car that can fly like an airplane and transport like a jumbo but with the facility to dive under the sea. And all of these applying restrictions to what C++ can do very well, just because something has decided that some features of C++ are "mistakes"!!

I have studied completely D and I am sure that this is another language that will make some little noise but will disappear very zoon. It do not have all the libraries tha has C++, D is not compatible with C (the most used language in the world), their compiler is totally new and it belong to a company so prepare to suffer from a lot of restrictions if you use it.

D is being conceived under the idea that C++ has some "mistakes" (who decide this?) and buala, Digital Mars will create a totally new language free of all these "mistakes".

Only one question: Are you sure that D don't have a lot of totally new mistakes?

For instance, Digital Mars has decided that multiple inheritance is a mistake so, they have removed it from D. Personally I think that this is a mistake in D.

Digital Mars has decided that new and delete are a "mistake" so they have created D without pointers and free memory management. They have included a garbage collector for the memory management. Digital Mars thinks that the memory management is so important that it must be assigned only …

Maritimo 15 Junior Poster in Training

Your problem can be fixed just adding two parenthesis.

The idea is to put your str string into a scope {/*...*/} and, at the end of the scope, your str string memory will be automatically released.

//...
fileIn.open(fileName, ios::in | ios::binary);
{
    string str((istreambuf_iterator<char>(fileIn)), istreambuf_iterator<char>());  
    cout << str << endl;
} // str will be automatically deleted here.
//...
Maritimo 15 Junior Poster in Training

If you don't want to programm your own random number generator but instead want to use something done, C++11 have a complete random number library defined in <random>. There, the standard library defines facilities for generating (pseudo-)random numbers with different distributions. I consider this library one of the most complete and advanced random number generator that exist. So, take a look to it.

Google "C++11 random number" to find tutorials.

Maritimo 15 Junior Poster in Training

2) Are there any memory-specific issues that the below code will encounter?

Yes, your first call to push_back will fail, for example, because iterator first do not point to any memory. To solve this, you must create the constructors and destructor.

4) My "String List" is not complete, but are there any other glaring issues I might look into?

Yes. You must create basically seven member functions to your String_list that are fundamental and you didn't:

  1. Ordinary constructors
  2. Default constructor
  3. Copy constructor
  4. Move constructor
  5. Copy assigmment
  6. Move assigmment
  7. Destructor

In all of your classes you always must take care of all of this seven member functions. You have several alternatives to do this, you can code all of them, leave some of them to be created by default or specify that they must not be created with = delete in c++11.

You must define a group of "invariants" like: 1) iterator first point to an array of strings pointers, 2) iterator last point to the last plus one string pointer and 3) list_size indicates the number of elements. You must initialize your String_list class forcing this invariants with all of your contructors and keep this invariants with all of your member functions. Finally you must liberate all your resources with your destructor. Your String_list is not doing nothing of these!!

Maritimo 15 Junior Poster in Training

1) Is this statement correct: In memory, elements of an array are stored "against" each other (I think more precisely, contigious space is allocated for them?) and a pointer to an array points to the first element.

Yes it is correct.

Maritimo 15 Junior Poster in Training

Sorry, I don't agree with mike. It is perfectly posible to create a library to work with std::deque<foo>& compiled with -O3 and work with other code compiled with -Og. You don't need to have the all the libraries compiled with every combinations of flags to link with your program. For example, you can use sqrt, malloc and printf compiled with different flags and different compiler on the c library into your new program. The linker do not specify that all the functions must be compiled neither with the same optimization flags nor the same compiler. Even, it is possible to link functions compiled in different languages.

So the idea is to create a "library" to work with std::deque<foo>, test and debug it and then compile it with -O3. Later link this verified library with your code compiled with -Og. Please note that calling those optimized files a "library" is just a name; you really need the *.o compiled with -O3 files to link with. But if you really want you can create a static library or even a dynamic library to work with std::deque<foo>.

Obviously, if later you change you foo class, you will need to recompile your library. If this is a problem, you can also create a library to work with std::deque<foo*> that will not have this dependency problem. Also you can consider to create a precompiled full optimized library to work with std::deque<void*> and later use "translation" functions from foo* to void* compiled with -Og.

Finally, when …

Maritimo 15 Junior Poster in Training

First I recommend making your board two rows bigger and two columns wider so you will not change your code when you are at the border. You must 'mark' the boxes that are out of the bord with some special value.
Then, if you are at the position r,c, for example, the diagonals will be at positions r+1,c+1, r+1,c-1, r-1,c+1 and r-1,c-1.
I don't know if this answer your question or I am not undertanding you.

Maritimo 15 Junior Poster in Training

Just to start:

class Shape2D
{
public:
   double area() = 0;
};

class Paralelogram : public Shape2D
{
public:
   double perimeter() = 0;
};

class Circles : public Shape2D
{
public:
   double diameter() = 0;
   double circunference = 0;
};

class Shape3D
{
public:
   double volume() = 0;
};

class Square : public Paralelogram
{
public:
   double area() {return with*with;}
   double perimeter() {/*...*/}
private:
   double with;
};

class Rectangle : public Paralelogram
{
public:
   double area() {/*...*/}
   double perimeter() {/*...*/}
private:
   double with, height;
};

//......

Hope this will help you.

Maritimo 15 Junior Poster in Training

Well, my fee is $1100 USD but it don't have a time limit.

Maritimo 15 Junior Poster in Training

Probably you don't need to go with the debuger to all of your functions. In that case, I also sujest you to compile some files with -O3 (where you are sure that everything is OK) and others (where you will need to debug) with the -Og option, following the NathanOliver advice.
To do this, you can extract some parts of your code into functions that you put on separated files that you compile with -O3. I guess you don't need to have the power to instect into the debuger the std::deque, for example.

Maritimo 15 Junior Poster in Training

Give more information, for example, your thesis will be in computer science?

Maritimo 15 Junior Poster in Training

If you want to count the total numbers of ; in your file, don't use an array int dotcoma[150], just use a simple variable int dotcoma and increment it when you find a ;.
On the contrary, if you want to count the number of ; on each line, do what you are doing but, at the end, print all the array.

Maritimo 15 Junior Poster in Training

Your program should structure something like this:

int low=1;
int high=100;
while(low<high)
{
   int half=(low+high)/2;
   std::cout << "Is your number greather than " << half <<"? (Y/N): ";
   char answer;
   std::cin >> answer;
   if(answer == 'Y' || answer == 'y') low=half+1;
   else                               high=half;
}
std::cout << "\nYour number is: " << low << std::endl;

You should also add some control into the answer and thats it.

Maritimo 15 Junior Poster in Training

I don't think this web is to teach how to crack a programm. Anyway, if you want to crack a code, you need to know a lot that seems you don't. So I recomend don't try to solve this here, you must study a lot. Your first step shuld be to learn assembler.

RikTelner commented: I'm here to get knowledge, if you're here to throw me objections then go somewhere else. Nobody talks here about me learning how to crack, I found it interesting and then I found new questions on horizon, which I post here. +0
Maritimo 15 Junior Poster in Training

The same question had been asked on C++ forum.

Maritimo 15 Junior Poster in Training

Replace

#define TRUE = 1;
#define FALSE = 0;

with

#define TRUE 1;
#define FALSE 0;

I don't know what you program must do but with this replacements there should not be more compiler errors. Good luck.

Maritimo 15 Junior Poster in Training

Taking into account that:

If a number N ends in zero then the remainder of N integer divided by ten is zero

You could count the number of zeroes inside a number N with the following algorithm:

Initialize Counter to zero
While N is greather than zero
  IF N ends in zero then increment Counter
  Integer divide N by ten
End while
Print Counter.
Maritimo 15 Junior Poster in Training

Maazu: Following with this programming style open example, should be very interesting and instructive if you can show the modifications to implement your idea of client/server model. Hope you have the time to do that.

Maritimo 15 Junior Poster in Training

Well, this project really is from Lilgenski16. I did it completelly because I wanted to use it as an example as a programming style in the forum to be commented by everybody. My idea was to show that the original program did by Lilgenski16 is to long and dificult to undertand (in my opinion) and my solution, based on exacly the same idea, is very more compact and, I think, more easy to be undertand. Obviously all of this this is subject to debate.

Maritimo 15 Junior Poster in Training

You need to include a for clause to delete the required column on every row:
for(auto& r : vec) r.erase(r.begin()+col)

Maritimo 15 Junior Poster in Training

I recomend you to use strings, neither chars nor pointers.
#include <string>
and then
string s = "Ctor of class Brain Called";
finally
void Taxi::PrintTaxi(const string& a)
Remember, you are using c++ not c.

Maritimo 15 Junior Poster in Training

Following your recomendations, the operator<< of class Card must be changed to:

ostream& operator<<(ostream& os, const Card& card)
{
  switch(card.m_Rank)           
  {
    case Card::ACE:   os << "A"; break;  //        Program Hierarchy       |
    case Card::TWO:   os << "2"; break;  //                                |
    case Card::THREE: os << "3"; break;  //             GroupOfCards       |
    case Card::FOUR:  os << "4"; break;  //               /     \          | 
    case Card::FIVE:  os << "5"; break;  //              /       \         | 
    case Card::SIX:   os << "6"; break;  //             /         \        | 
    case Card::SEVEN: os << "7"; break;  //    (v)GenericPlayer   Deck     | 
    case Card::EIGHT: os << "8"; break;  //         /       \              | 
    case Card::NINE:  os << "9"; break;  //        /         \             | 
    case Card::TEN:   os << "10";break;  //       /           \            | 
    case Card::JACK:  os << "J"; break;  // (v)Player        House(v)      | 
    case Card::QUEEN: os << "Q"; break;  //                                | 
    case Card::KING:  os << "K"; break;  // (v):virtual                    | 
  }                     

  switch(card.m_Suit)               
  {
    case Card::CLUBS:    os << "\u2663"; break;
    case Card::DIAMONDS: os << "\u2666"; break;
    case Card::HEARTS:   os << "\u2665"; break;
    case Card::SPADES:   os << "\u2660"; break;
  }

  return os;
}

With this, some play can look like:

-------------------------------------------------- Lets go:
Player a: 10♣ 4♥  (2 cards)
Player b: 5♣ 5♥  (2 cards)
Player c: J♥ Q♠  (2 cards)
House:  (2 cards)

Player a, do you want a hit? (Y/N): y
Player a: 10♣ 4♥ 3♥  (3 cards)
Player a, do you want a hit? (Y/N): n

Player b, do you want a hit? (Y/N): y
Player b: 5♣ 5♥ K♣  (3 cards) …
Maritimo 15 Junior Poster in Training

Hi, you can do something like this:

//...

cout<<"Do you want to continue (Y/N): ";
        cin>>t;
if (t == "Y" || t == "y") break; // Or any other way to get out of the f(;;) loop like exit();

cout<<"Please enter the ticket type:F,B,or E: ";
        cin>>t;

//...