deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do you think I have an obsession or a passion with tech and software?

Passion, yes. Borderline obsession too. Not that there's anything wrong with it as long as it doesn't take over your life; I have a similar passion when it comes to software development.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Another potential issue with hardware changes is you may need to reactivate Windows. Typically this only happens with significant changes like a motherboard replacement, but it's not unheard of for minor hardware changes or even non-hardware changes to trigger a reactivation notice.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do your own homework.

Thank you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually the printf() statement will work according to the stack mechanism i.e., the evaluation (execution) will starts from right side to left side...

Yet the compiler is free to actually evaluate the arguments in any order at all. Just because the values might be pushed from right to left doesn't mean the expressions used to produce a value will be evaluated in the same order.

Modifying a variable multiple times between sequence points is undefined behavior. All predictability is gone, even between runs of the program from the same compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nice tutorial. I'll also add that there are usually two situations where forms communicate that affect your choice of how to do it:

  1. The forms are not modal and the lifetime of the child form is either long or independent of the code that creates it. In this case the event approach is suitable.

  2. The child form represents a modal dialog. In this case two way events are overengineered; a better approach uses public properties and is vastly simpler:

    using (var dlg = new ChildForm())
    {
        if (dlg.ShowDialog() == DialogResult.OK)
        {
            // Whatever other stuff you want to do...
    
            textBox1.Text = dlg.Name;
            textBox2.Text = dlg.EventType;
        }
    }
    

Your tutorial covers the first case quite well, but doesn't cover the second. I just wanted to point that out for readers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A static data member belongs to the class rather than to an individual instance of the class. Likewise with a static member function. A reasonable way to think about them at a high level is to treat the class as acting like a namespace for those members:

class Foo
{
public:
    static int bar;
    static void baz();
};

...

int main()
{
    cout << Foo::bar << '\n';
    Foo::baz();
}

Comparable in many cases, but not identical is the namespace concept:

namespace Foo
{
    int bar;
    void baz();
}

int main()
{
    cout << Foo::bar << '\n';
    Foo::baz();
}

In both cases you can use the name of the class or namespace as a qualifier to access the member. With classes you can also access static members through an object:

int main()
{
    Foo obj;

    cout << obj.bar << '\n';
    obj.baz();
}

Under the hood, the Foo class can be imagined something like this:

int static_cls_Foo_public_bar;
void static_cls_Foo_public_baz();

class Foo {};

bar and baz are actually closer to global objects that are internally checked for correct visibility and access by the compiler. The objects themselves are not baked into an instance, but still tied closely to the class.

When would you use a static member? Well, whenever you need an object or function that applies to all instances or to the class as a whole. One good example is reference counting. If you're counting the number of instances, then each instance having an …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You've encountered a common beginner issue. Allow me to point it out more clearly:

// This is a pointer to a string literal. You can't modify it.
char *text = "GOOOD TEXT ALL TIME VERY POOR ";

// This is an uninitialized pointer, you can't read from or write to
// it until it points to a valid block of memory that you own.
char *copy_text;

// This is undefined behavior because you're trying to write
// to an uninitialized pointer. If you're lucky, the program
// will crash fantastically so that the error is obvious, but
// there's no guarantee of that.
StrCpy( copy_text, text );

Now let's fix it:

char *text = "GOOOD TEXT ALL TIME VERY POOR ";
char copy_text[50];
StrCpy( copy_text, text );

In the above correction, copy_text is an array. This means you own the memory, and it's large enough to hold all of the characters in text.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The laziness here is impressive. Most drive-by cross posters will at least have the courtesy to copy their other posts verbatim rather than linking to them. Did you read the answer to the question on that other forum? It provides a valuable hint for research.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An array is a collection of items. To access individual items you need to specify which index in the collection you want (ranging from 0 to N-1):

for (int i = 0; i < months30.Length; i++)
{
    if (months30[i] == month) // Now you can test against the entered month
    {
        Console.WriteLine("{0} has 30 days", month);
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Help whom? The original poster is 3 years gone.

The original poster isn't the only person a thread might help, that's why we don't close threads after they reach a certain age.

It could be helpful for u if u had brain.

Malicious personal attacks will not be tolerated, please keep our rules in mind.

cuz you dont own this community........

Nor do you. It's generally frowned upon when a new member tries to play net nannie. I'd suggest that if you feel any rules are broken, simply report the offending post and let those of us who were selected by the owner of this community to enforce those rules handle it. Taking matters into your own hands is a good way to find yourself in the wrong and subject to moderator action.

kplcjl commented: Thanks, for how you handled both of us because we were both wrong in how we reacted. I later felt an idiot for reacting to a post. +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The closest you can get would be a static class in C# with those variables as members. Place that class in a shared assembly (if your project uses more than one assembly) and you're good to go.

GagaCode commented: thaks +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your code performs precisely zero length, existence, or success checks, so it's absolutely vulnerable to malicious use. It's also brittle in the face of legitimate use. Let's add a few checks to make it better:

#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]) {
    char *first, *second;

    first = malloc(888);
    second = malloc(22);

    if (first != NULL && argc > 1) {
        first[0] = '\0';
        strncat(first, argv[1], 887);
    }

    if (second != NULL && argv > 2) {
        second[0] = '\0';
        strncat(second, argv[2], 21);
    }

    free(first);
    free(second);

    return(0);
}

Of course, in practice the arguments may be required and/or related to each other, in which case the tests would be different. Right now they're entirely independent.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

From the end of the string walk backward until you find a non-blank character, then overwrite the last blank you saw with '\0'. Easy peasy, and here's a working example of an rtrim function to get you rolling.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Of course, since you still have the assignment and saying it's stupid won't accomplish much, a reasonable approach would be to compress your range with a loop and table lookup:

int lookup[] = {21, 41, 61, 81};
int discount = 0;

for (int i = 0; i < sizeof lookup / sizeof *lookup; i++)
{
    if (qty < lookup[i])
    {
        break;
    }

    discount += 5;
}

switch (discount)
{
case 0:
    // Blah
    break;
case 5:
    // Blah
    break;
case 10:
    // Blah
    break;
case 15:
    // Blah
    break;
case 20:
    // Blah
    break;
}

But if you're already finding the discount with the lookup, I'd question whether a switch is even needed. It might be able to be rolled up into little more than a final price calculation and output statement.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It largely depends on your compiler and switches. C++11 (the latest standard) added this feature, and some compilers prior to that offered it as an extension.

Your book is old, by the way, and also written by an author who's routinely mocked for making grievous beginner mistakes. You might consider getting a different one.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What other languages support is irrelevant, this is C. While I can understand the confusion, that doesn't change the importance of making it clear what's standard C and what's not.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

actually till now we dont use string::size_type :(

Till now, that's what we call learning. ;) size_type is the type string::find returns, and it's the type string::substr accepts.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Reading the documentation for substr and find would be helpful, it highlights that the second argument is a count of characters, not a position in the string. find gives you the position in the string and also accepts a starting position, so a little munging of data is needed:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string sentence;

    cout << "enter a three-words sentence :";

    if (getline(cin, sentence))
    {
        string::size_type middle_begin = sentence.find(" ") + 1;
        string::size_type middle_end = sentence.find(" ", middle_begin);

        string middle = sentence.substr(middle_begin, middle_end - middle_begin);

        cout << "'" << middle << "'\n";
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think it is possible to do that, only that, the nested function is only been seen within the function in which they are defined.

Not in standard C. If nested functions works for you then you're relying on a compiler extension.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

32 or 64 bit? With 32 bit you have a hard 4GB limit, 3GB and change of which would be usable to applications. For 64 bit that physical limit is raised to between 8GB and 192GB depending on your specific version of Windows 7:

Home Basic: 8GB
Home Premium: 16GB
Everything Higher: 192GB

Home Starter has a hard limit of 2GB and 32 bit, but it's somewhat rare to see that version in the wild because it's so very limited.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd actually recommend against learning your first two languages simultaneously because you're also learning programming in general at that time. Too much information, some of it guaranteed to be conflicting due to varying syntax rules, will prove to be confusing and slow your progress.

So if you're happy with Python so far, keep learning just Python until you feel sufficiently learned or have need for a different language. That's my advice.

Once you reach that point, unless you need something different, of course, my suggestion would be Java, C#, or VB.NET.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Those specs are fine, though more RAM never hurts. My dev machine at work has 8GB and my home PC has 16GB. A stronger CPU would be your second upgrade as necessary.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C++ and C# are both imperative languages, so if you learn one, learning the other will be straightforward. The goal is to learn logic and problem solving; language syntax and libraries are a relative cake walk with a strong foundation in the basics.

My recommendations for languages if your goal is to become a pro are as follows:

  • Python: A good beginner's language that's also powerful.
  • C++: The most likely 1st language for serious games.
  • C# or Java: Depending on your target platform (C# for Windows, Java for multi-platform), the two languages themselves are actually very similar.
  • Assembly: Good for low level knowledge, even though you probably won't use it often.
  • A LISP Variant: Not strictly necessary, but offers a significant "aha!" moment when you get it, and greatly helps an understanding of recursion.

C# can be used outside of Windows, of course, but the .NET framework is by far the more common target.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's a starting point:

#include <ios>
#include <iostream>
#include <limits>

using namespace std;

int main()
{
    unsigned value;

    cout << "Please enter a positive number: ";

    while (!(cin >> value) || value < 0)
    {
        if (!cin)
        {
            cout << "Invalid input\n";
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(), '\n');
        }

        cout << "Please enter a positive number: ";
    }

    cout << "You entered " << value << '\n';
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

its a perfect program of time conversion

Well, it's not horrible, but I wouldn't use the word "perfect" as a descriptor. You could start by learning to format your code in a sane manner.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is Google?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

TextQuery(inFile);

You're not defining an object there. Try this instead:

TextQuery tq(inFile);
Vasthor commented: sorry for creating bad question, this whole hours of thinking where is the fault is a lie :( +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For the most part, whitespace in C is ignored. All three of your examples are functionally identical. You could also say const char*buf and it'll work fine because the tokens aren't ambiguous. However, constchar won't work.

Another bit of trivia is that const doesn't have to go before the type: char const *buf. This can make declarations easier to decipher as they're typically read inside out and right to left: char const * const buf reads as "buf is a const pointer to const char".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We already have a chat feature. On the footer bar you'll find one quick way to get to it (the Chat button).

diafol commented: he heh - that was quick action! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The character(s) pointed to by buf are treated as read-only. To make the pointer itself const, place the keyword after the asterisk:

char * const buf;       // const pointer to non-const char
const char *buf;        // Non-const pointer to const char
const char * const buf; // const pointer to const char
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Having studied a second language I understand how difficult it can be. Understanding English and linguistics in general I can certainly understand difficulties learning English (it's far from simple even if you grew up with it). I totally respect anyone who isn't a native speaker and still tries.

Those that don't try get no respect. And yes, after well over a decade of particupating in forums such as Daniweb, I can tell the difference. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes.

rubberman commented: Well put! :-) +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There is no distinction between an array and a pointer this (1st) case.

Yes, that's close enough.

It looks like as if p is hidden array of pointers.

No, it's just a pointer. Since it points to the address of an item in an array, you can treat that pointer like an array to get other items. The concept here is that pointers give you largely unrestricted access to memory. If a char pointer (call it p) points to address 12345, you can use *(p + 1) to get the value at address 12346. Because array indexing is just syntactic sugar for pointer arithmetic, that means you can also say p[1] for the same effect.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C99 concept of variable array is not accepted in Recent Compilers .They give errors like" Constant Expressions required in Function main on line 9"

Then you're not compiling as C99. The compiler also must support C99, which not all recent compilers do. Further, it looks like you're using Turbo C, which is not a recent compiler by any measure.

However, that said, I don't recommend this feature even if it's supported (for various reasons I won't elaborate on unless asked). I'd recommend using a pointer and dynamic memory allocation.

But after little modification Every thing went correctly by Initializing a dummpy value to an array and making it as global.

Your code is broken. At the point of the array definition, n is uninitialized, which invokes undefined behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

*p=&a or *p=a will assign base address to p, which is equivalent to *p=&a[0].

Type matters, even if the addresses are all the same. *p = &a assigns a pointer to 2D array (ie. int(*)[2][3]) to a pointer to int, thus a type mismatch. *p = a assigns a pointer to a 1D array (ie. int(*)[3]) to a pointer to int, also a type mismatch. Only *p = &a[0] will do what you want, which is assign a pointer to int to another pointer to int.

So p[4] is same as *(p+4) ?

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Someone please point out where is loophole in my knowledge.

The missing link is sequence points and undefined behavior. In c=(--a)+(--a);, a is being modified multiple times between sequence points, which invokes undefined behavior. The compiler is under no obligation to do anything predictable.

Your second attempt removes the undefined behavior, and thus it works as expected and predictably.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But what if unknown coder is smart enough to change hidden data of class?

Then unknown coder will be breaking the contract and if the hidden data of the class ever changes, will suffer the consequences of not strictly using the public interface provided by the class author. I see no issue here. It's like saying that people who know how to pick locks will be able to break into your house, and because of that, locks have no advantages.

To conclude with, is not OOPs a simple agreed process we are following which may or may not help to protect data?

As ddanbe said, data hiding is not data security. It's a strategy for hiding things the user of the class doesn't need to use the class, or for hiding implementation details that may change in future revisions of the class.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two options. One is a verbatim string:

var query = @"select beggining_school,
end_school FROM Student,student_weekend,Weekend WHERE 
Student.ID=student_weekend.studentID AND 
student_weekend.WeekendID=Weekend.ID"

Note that indentation is significant in the string, as are newlines. The other, my preference, is literal concatenation because there aren't any "hidden" characters:

var query = 
    "select beggining_school," +
    "end_school FROM Student,student_weekend,Weekend WHERE " +
    "Student.ID=student_weekend.studentID AND " +
    "student_weekend.WeekendID=Weekend.ID"
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let's start with one quick clarification, XML is a text format. So technically you can save XML to a .txt file. ;)

I just can t see xml being a advanced technology for data saving and transportation.

That's because it's not. XML isn't the most human readable format out there, and it's very verbose. The cost of formatting versus actual data is high enough that you could describe XML as a wasteful text format.

On the other hand, XML is well known, very well supported by libraries and utilities, and an integral part of the .NET framework (think configuration files).

they always lack to provide an EXAMPLE WITH SOMETHING ELSE

I'm not sure why you would expect them to, unless they're arguing in favor of another format. In my experience, delimiter separated formats are the most common alternative to XML, but they tend to be less flexible.

castajiz_2 commented: tnx. +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Good luck. Feel free to ask for help when you have a question other than nothing at all or "I don't know where to start". :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is a quirk of the C++ object model. Since the member function isn't virtual, the compiler knows exactly what function to call and doesn't depend on the object instance being valid. Technically, all non-virtual member functions are shared under the hood (virtual member functions work through a lookup table stored in the object). When you say a->func(), the generated code looks more like this:

struct A
{
    int _dmember;
};

void __class_A_12345_func(A *self)
{
    cout << "Inside A!! " << endl;
    cout << self->_dmember;
}

...

int main()
{
    A *a = NULL;

    __class_A_12345_func(a);

    return 1;
}

Given a low level view of how things are set up, it's easy to see how a->func() will work just peachy when a is a null pointer. However, the problem is inside the function where you request the value of an instance data member, which invokes undefined behavior because a is a null pointer. I'd expect a crash at that point, but your compiler may generate code that supresses it for this case. Regardless, the code is broken because the function tries to access something that relies on a valid instance.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can make the insertion and deletion programs but not with these

Can you elaborate on what you mean by "but not with these"? The pseudocode is very specific and only needs to be translated to C++. The std::string class has member functions for finding the length, extracting a substring, and contatenation. I fail to see what the problem is.

Its not my homework

It's a beginner's exercise, and thus homework. The term "homework" as concerns our rules spans more than official assignments given to you by a teacher. It also includes exercises you take upon yourself for education purposes.

As such, you need to show proof of effort if you want help.

rubberman commented: Amen to that! +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you don't add any code to the event handler, simply resetting it in the control properties will delete the code as well. If you do add code (even if you delete it immediately), the best approach is to delete the handler manually and also reset it in the control properties.

If you want to go full manual, you can find where the handler is attached in your compiler generated code and remove that rather than do it from the designer.

castajiz_2 commented: TNX! +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you're posting to a C++ forum, I'm assuming you know at least rudimentary C++. So the good news is that when you need a program, you can write it.

The bad news is that we won't write it for you. That would be cheating at what is clearly homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It looks a lot like you just assumed I haven't started my homework because I didn't post what I have done.

Yup. I can only work with the available information. I notice that you still haven't posted what you've done or asked any real question. Please do so or I'll close this thread in violation of Daniweb's homework policy.

I appreciate you for stating your opinion, but that wasn't exactly what I asked for.

You didn't ask for anything, you just posted your homework assignment. Assuming that you're asking for someone to do it for you is not unreasonable. Your followup comment and downvote only suffice as further evidence of this assumption as being correct.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No. Do your own homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd create a class or structure for a course, then a class for a student that has a vector (or array if you so choose) of courses. Finally, I'd create a vector (or array if you so choose) of students and be good to go.

class Course
{
    ...
};

class Student
{
    Course _courses[5]; // Since you asked for arrays
    ...
};

Student students[10]; // Since you asked for arrays
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the value of x? Neither of the values in notename suggest a valid file name, and if they do, you'd need to verify that the file is in the current working folder. I'd suggest trying perror to get more information on why the file didn't open successfully:

if (!readnote)
{
    perror("Read Error");
}

You can find perror in stdio.h.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here is something I wrote up years ago, but it should still be relevant to your needs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am a programmer. That's why I'm receiving a paycheck. I sit alone in a small cubicle and do my work.

That's an interesting description of a programmer. I wish I could sit alone in my office and do my work without having to communicate with the rest of my team or end users, but that's not realistic. ;)

So my boss says to me today that I am being signed up for a FIVE day course in..... Microsoft OUTLOOK.

Unless the training involves teaching a component that you wrote, I'd agree that it's outside the scope of your job description as stated. That's not to say that your boss doesn't have a different idea of what your job description is, so the first step would be to get clarification and work from there.

If you're a programmer like me, what would you do?

I'd probably do it for the experience and to help out the users, but make it clear to my boss that this is outside the scope of my job description. I might also try to negotiate a bonus of some sort and have my boss handle scheduling and schmoozing of lost time for the days I wouldn't be doing the job I was hired for.

The last thing you want is to be punished for doing what was asked of you.