Jump to content



Photo

c++ Help


  • Please log in to reply
20 replies to this topic

#1 Jay Nguyen

Jay Nguyen

    Neowinian

  • Joined: 07-September 13

Posted 07 September 2013 - 02:20

I need to create a DOB out of OCCCDate in the person header file and then call it in the testOCCCDate.cpp. but i dont know how please help me..

 

here is my UML;

Person

#firstname: String

#lastName:String

DOB :OCCCDate/// i having problem creating this DOB... some1 help me please

Attached Files




#2 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 07 September 2013 - 04:41

What is a DOB and an OCCCDate? What's the context? What's the problem? Put some work in your question so others don't have to do that work to figure out what you mean.



#3 OP Jay Nguyen

Jay Nguyen

    Neowinian

  • Joined: 07-September 13

Posted 07 September 2013 - 12:04

DOB is Date Of Birth. OCCCDate is a Header file that i created.



#4 +Majesticmerc

Majesticmerc

    Resident Idealist

  • Tech Issues Solved: 8
  • Joined: 24-August 05
  • Location: United Kingdom
  • OS: Arch Linux / Win 7
  • Phone: HTC One X

Posted 07 September 2013 - 15:41

From what I understand, you want to add a  date of birth into the Person class.
 
Step 1
To begin, you'll need to add a date of birth field into the person class. You'll need to do this in two parts.
 
First, you need to include the OCCCDate class header file inside your Person.h header file...
 
Person.h
---------------------------------------------------------

//Person.h

#ifndef PERSON_H
#define PERSON_H
#include<string>

// Add the OCCCDate.h header file...
#include "OCCCDate.h"

...

Once you've added the header file, you can create a private class member inside your person class like you've described in your original post.
 
Person.h
---------------------------------------------------------

...

class Person{
    private:
        string firstname;
        string lastname;

        // Add an OCCCDate class here as a member, just like you did for the strings above.

    public:

...    
Step 2:
It's unlikely that you'll want a person to have the current system date as their date of birth, so you'll need to add a parameter to the Person constructor to pass a date of birth. like this:


Person.h
---------------------------------------------------------

...

class Person{

    private:
        ...

    public:
        Person(string firstName, string lastName, OCCCDate dateOfBirth);
//                                                ^--------,---------^
//                                                         New parameter in the constructor.

...    
Don't forget you'll need to copy the date of birth parameter in the constructor in your Person.cpp file too! Looking at your .cpp file, you're almost there already :)).

Once you've done that, you can add a method to the Person class to retrieve the date of birth (just like Person::getFirstName() and Person::getLastName()), and you're good to go!

Hope this helps :)

#5 OP Jay Nguyen

Jay Nguyen

    Neowinian

  • Joined: 07-September 13

Posted 07 September 2013 - 18:14

When i I use #include "OCCCDate.h" in the person file it gave me more error.

Attached Files



#6 OP Jay Nguyen

Jay Nguyen

    Neowinian

  • Joined: 07-September 13

Posted 08 September 2013 - 08:05

bump?



#7 +Majesticmerc

Majesticmerc

    Resident Idealist

  • Tech Issues Solved: 8
  • Joined: 24-August 05
  • Location: United Kingdom
  • OS: Arch Linux / Win 7
  • Phone: HTC One X

Posted 08 September 2013 - 16:25

I assume you're seeing an error talking about "redefinition of class OCCCDate"? That's because of the following lines in OCCCDate.h...
 
//file OcccDate.h

#ifndef OCCCDATE_H
#define OCCCDDATE_H
See the spelling mistake in the #define line (hint: two 'D's in DDATE)? You'll need to fix that like this...
 
//file OcccDate.h

#ifndef OCCCDATE_H
#define OCCCDATE_H
Once you fix that, it should work. Because of the spelling mistake, the #ifndef block was always TRUE (because OCCCDATE_H was never defined), and the compiler tried to define the class again, which is bad ;).

#8 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 08 September 2013 - 17:26

Or you could just use #pragma once rather than #ifndef #define #endif. All major compilers (MSVC, GCC, Clang, Intel, etc.) support it and it reduces the potential for bugs. Like the one you just had.



#9 OP Jay Nguyen

Jay Nguyen

    Neowinian

  • Joined: 07-September 13

Posted 08 September 2013 - 20:00

WOW just that small mistake and it took me 3 days. jesus. programming is so hard.



#10 +Majesticmerc

Majesticmerc

    Resident Idealist

  • Tech Issues Solved: 8
  • Joined: 24-August 05
  • Location: United Kingdom
  • OS: Arch Linux / Win 7
  • Phone: HTC One X

Posted 08 September 2013 - 20:17

Or you could just use #pragma once rather than #ifndef #define #endif. All major compilers (MSVC, GCC, Clang, Intel, etc.) support it and it reduces the potential for bugs. Like the one you just had.


While I agree with you in practice, if it's an assignment it may be that the tutor is sticking strictly to the standard, and using #pragma vs a standard-compliant alternative may lose the student points.

WOW just that small mistake and it took me 3 days. jesus. programming is so hard.


Indeed it is, but its also incredibly gratifying if you enjoy it. Glad your issue is sorted. :)

#11 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 09 September 2013 - 03:37

WOW just that small mistake and it took me 3 days. jesus. programming is so hard.

No, C++ is just ****. No decent programming language uses header files and silly macro tricks just to get programs to compile. Don't let your opinion of programming be tainted by the arcane and irrelevant rules of C++, even though it happens that this is what your teacher misleadingly thought would be a good idea to show you first. If your teacher thinks C++ is good just ask him "why are there header files in C++?" and watch him be embarassed. I fondly remember being unable to receive an intelligent answer to this question in my first programming class.

 

It ****es me off to think many people must quit programming simply because they're being shown the most bizarre and capricious language in existence first, and assume that all programming must be like that. It's not.

 

Arm yourself with courage and a good C++ book (I used The C++ Primer Plus by Stephen Prata), and when you're through with this course, take a look at such beautiful languages as Python, C#, F#, Scala, Rust, etc. I guarantee your outlook on programming will change for the better and dramatically so.



#12 FloatingFatMan

FloatingFatMan

    Resident Fat Dude

  • Tech Issues Solved: 1
  • Joined: 23-August 04
  • Location: UK

Posted 09 September 2013 - 07:15

No, C++ is just ****. No decent programming language uses header files and silly macro tricks just to get programs to compile. Don't let your opinion of programming be tainted by the arcane and irrelevant rules of C++, even though it happens that this is what your teacher misleadingly thought would be a good idea to show you first. If your teacher thinks C++ is good just ask him "why are there header files in C++?" and watch him be embarassed. I fondly remember being unable to receive an intelligent answer to this question in my first programming class.

 

It ****es me off to think many people must quit programming simply because they're being shown the most bizarre and capricious language in existence first, and assume that all programming must be like that. It's not.

 

 

That said, he didn't exactly help himself with that function name. VERY easy to mistype that, so I'm not at all surprised he didn't spot it...



#13 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 09 September 2013 - 14:22

That said, he didn't exactly help himself with that function name. VERY easy to mistype that, so I'm not at all surprised he didn't spot it...

At least when you mistype something in most programming languages, you tend to get something from the compiler like "hey what's that you typed in file (Z) at line (X) column ( Y), I have no idea what that is." In C++ you tend to get the equivalent of "AAAAAAaaaaarglgl.... guh." Much of the difficulty consists of learning how to map the gibberish to actual errors.



#14 FloatingFatMan

FloatingFatMan

    Resident Fat Dude

  • Tech Issues Solved: 1
  • Joined: 23-August 04
  • Location: UK

Posted 09 September 2013 - 14:27

At least when you mistype something in most programming languages, you tend to get something from the compiler like "hey what's that you typed in file (Z) at line (X) column ( Y), I have no idea what that is." In C++ you tend to get the equivalent of "AAAAAAaaaaarglgl.... guh." Much of the difficulty consists of learning how to map the gibberish to actual errors.

 

Pretty much why I walked away from C/C++ 2 decades ago. :p  Sure it's handy, but it's a pain in the backside, too!



#15 ILikeTobacco

ILikeTobacco

    Neowinian Senior

  • Joined: 08-July 10

Posted 09 September 2013 - 14:29

WOW just that small mistake and it took me 3 days. jesus. programming is so hard.

It isn't hard. Just tedious and annoying lol. It's always the little things that mess you up in programming.