d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Make Me A Better Programmer - From Step 1
Prev1131415161756Next
Add Reply New Topic New Poll
Member
Posts: 1,007
Joined: Oct 30 2012
Gold: 0.18
Nov 20 2012 05:13am
ye
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 20 2012 05:16am
Quote (ShingXiouYingChauLing @ Nov 20 2012 06:13am)
ye


thanks bro great post A++ would read again
Member
Posts: 4,541
Joined: Sep 15 2011
Gold: 10,391.00
Nov 20 2012 12:44pm
you're not a bad student - this stuff takes time to develop, especially the way you think about these problems. but there's the rub - you need to be developing how you think about these problems as you're doing these assignments. but mostly... don't worry about it - it'll come.

that said, it's probably worth it to let yourself spend more time banging your head against stuff rather than just asking for help... especially on here, where some folks have the tendency to just give you an answer. my first substantial programming/software engineering class was more than a full-time job in terms of workload. the only way to get better is to put in the time.

This post was edited by irimi on Nov 20 2012 12:45pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 20 2012 06:07pm
well I just had what seems like a good idea and seems to make more sense

I think I will just add a pointer to person called sibling inside the class


I got this much to work so far, though the sheer amount of setters is a pain.

Code
class person
{
       string name;
       string birthdate;
       char marital;
       person *spouse;
       person *kids;
       person *sibling;
       string deathdate;
   public:
       void set_name (string input)
       {
           name = input;
       };
       void set_birthdate (string input)
       {
           birthdate = input;
       };
       void set_marital (char input)
       {
           marital = input;
       };
       void set_spouse()
       {
           spouse = new(person);
       };
       void set_spouse_name(string input)
       {
           spouse->name = input;
       };
       void set_kids()
       {
           kids = new(person);
       };
       void set_kids_name(string input)
       {
           kids->name = input;
       };
       void set_sibling()
       {
           sibling = new(person);
       };
       void print_all();
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 20 2012 06:36pm
Quote (irimi @ Nov 20 2012 02:44pm)
  my first substantial programming/software engineering class was more than a full-time job in terms of workload.  the only way to get better is to put in the time.


Sounds useful. In most classes i spent around 2-6h biweekly. in the project classes i only spent around 20h of coding throughout the whole semester
Member
Posts: 4,541
Joined: Sep 15 2011
Gold: 10,391.00
Nov 20 2012 06:53pm
Quote (carteblanche @ Nov 20 2012 05:36pm)
Sounds useful. In most classes i spent around 2-6h biweekly. in the project classes i only spent around 20h of coding throughout the whole semester


Well, it probably had less to do with the class and more to do with my own noobness. I think some other folks in the class who had some level of programming experience spent maybe a quarter of the time (if not even less) that I did on the problem sets.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 20 2012 08:09pm
Thinking of using a tree traversal-ish function to search for someone and print their shit.

Still need to figure out how I will handle moving the pointer from person1 to his kid(s) but I have the class and some setters done.

Also made a constructor which sets the values of the pointers to NULL and sets everything else to some temp string or character.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 21 2012 01:38am
I've been spending all night BUILDING various shit.

I'll post it here and would really enjoy some GUIDANCE (not a solution per se) but if that is unavailable then I will just post it for reference I guess :/

Code

#include <iostream>
#include <ctype.h>
#include <string>
using namespace std;

const string EMPTY = "EMPTY";

class person
{
       string name;
       string birthdate;
       char marital;
       person *spouse;
       person *kids;
       person *sibling;
       string deathdate;
   public:
       person ();                      //HOW MANY OF THESE DO WE REALLY NEED?
       void set_name (string input)
       {
           name = input;
       };
       void set_birthdate (string input)
       {
           birthdate = input;
       };
       void set_marital (char input)
       {
           marital = input;
       };
       void set_spouse()
       {
           spouse = new(person);
       };
       void set_spouse_name(string input)
       {
           spouse->name = input;
       };
       void set_kids()
       {
           kids = new(person);
       };
       void set_kids_name(string input)
       {
           kids->name = input;
       };
       void set_sibling()
       {
           sibling = new(person);
       };
       void set_sibling_name(string input)
       {
           sibling->name = input;
       };
       void access_kids(person *&head)
       {
           head = head->kids;
       };
       void access_spouse(person *&head)
       {
           head = head->spouse;
       };
void access_sibling(person *&head)
       {
           head = head->sibling;
       };
       friend void head_return(person *&head, person *target);
       void print_all();
       bool search(string input, person *head);  //DEFUNCT ATM. TRY TO FIX LATER? (POSSIBLY RETURN VALUE?)
       friend void input_handler(string input, person *head); //STILL IN PROGRESS!! ARE WE DOING IT RIGHT??
       friend void add_kids(person *&head, string input); //DOES THIS WORK THE RIGHT WAY?? TEST!!




};

person::person()
{
   name = EMPTY;
   birthdate = EMPTY;
   marital = 'x';
   spouse = NULL;
   kids = NULL;
   sibling = NULL;
   deathdate = EMPTY;
}

void head_return(person *&head, person *target)
{
   head = target;
}

void person::print_all() //THIS IS A FUNCTION FOR TESTING PURPOSES ONLY!!
{
   cout << name << endl;
   cout << birthdate << endl;
   cout << marital<< endl;
   if (spouse != NULL)
   {
       cout << spouse->name << endl;
       cout << spouse->birthday << endl;
   }
   if (kids != NULL)
   {
       cout << kids->name << endl;
       cout << kids->birthday << endl;

}

void add_kids(person *&head, string input)
{
   if (head == NULL)
   {
       head = new(person);
       head->name = input;
       return;
   }
   head->access_sibling();
   add_kids(head, input);
}

bool person::search(string input, person *head) //SEG FAULTS!! FIX??
{
   if (head == NULL)
       return false;
   if (head->name == input)
   {
       head->print_all();
       return true;
   }
   if (search(input, spouse))
       return true;
   else if (search (input, kids))
       return true;
   else if (search (input, sibling))
       return true;
   else return false;
}

void input_handler(string input, person *&head)
{
   person *root = head;
   string temp;
   int pos;

   while (!input.empty())
   {
       pos = input.find_first_of(' '); //DONT FORGET THE SPECIAL CASES (X AND QUIT)
       temp = input.substr(0, pos-1); //IS THIS THE RIGHT WAY TO ALLOCATE??
       if (head->name == EMPTY)
           head->name = temp;
       else if (head->birthday = EMPTY)
           head->birthday = temp;
       else if (head->marital == 'x')
           head->marital = temp;
       else if (head->marital == 'S')
           {
               if (isalpha(temp[0]))
               {
                   head->access_kids();
                   add_kids(head, temp);
                   head_return(head, root);
               }
               else head->deathday = temp; //IS THIS CORRECT?

       if (temp.length() > 1)
       {
           if (isalpha(temp[0])
           {
               if (head->name == EMPTY)
                   head->name = temp;


Don't mind the awkward comments and various gaps of missing code...like I said I haven't made terribly much progress, if ANY at all.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 21 2012 07:26am
Interesting thread.

I'm surprised to see that someone actually cares about learning for a change.

Keep it up. You'll improve with time; As goes with anything in life. :)
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Nov 21 2012 09:02am
Quote (Muted @ Nov 21 2012 08:26am)
Interesting thread.

I'm surprised to see that someone actually cares about learning for a change.

Keep it up. You'll improve with time; As goes with anything in life.  :)


A blast from the past.
Go Back To Programming & Development Topic List
Prev1131415161756Next
Add Reply New Topic New Poll