NewStats: 3,261,375 , 8,173,826 topics. Date: Thursday, 29 May 2025 at 04:04 AM 4die

6z3e3g

C++ Gurus: Urgent Help Needed. - Programming - Nairaland 6q445k

C++ Gurus: Urgent Help Needed. (1413 Views)

(4)

(1) (Go Down)

kode12: 6:44pm On May 15, 2017
To all C++ gurus in the house please help, I have been battling with this project for a while but i cant seem to get my head around it. I am learning C++ and i have an assignment to extend the functionality of some codes but i cant seem to understand the question or how to go about achieving it. Any help in doing this will be greatly appreciated. Attached are the codes that should be extended and the assignment.





# include <iostream> // An header file for I/O operations
using namespace std; // For Uniqueness

class Date
{
int day;
char * month;
int year;
// class attributes: they are private by default

public:

void ManageDate(int d, char* M, int y) //// initialization of actual parameters
{
day=d;
month=M;
year= y;
}

Date() //default constructor
{
day=0;
month="";
year=0;
}

Date(int D, char* m, int Y)
{
day=D;
month=m;
year = Y;
}

int getDay()
{
return day;
}

int getYear()
{return year;
}

char * getMonth()
{
return month;
}

};


class Student
{ //////////// Class Attributes Starts from Here ////////////
char * FirstName; // Non-static variable
string Surname;
int Age;
static int Level; // A static variable
Date * DOB; // An instance of class Date as an attribute of class Student

/////////////// Class Attributes Ends Here ///////////////
// The class attributes are public by default////////

public: //// change of access mode modifier from private to public

Student(int D, char* m, int Y):DOB(new Date(D,m,Y))
{
FirstName="";
Surname="";
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName,string S, Date * D) //// constructor with one argument/parameter
{
FirstName=FName;
Surname=S;
DOB=D;
Age=10;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, string SName,int D, char* m, int Y): DOB(new Date(D,m,Y)) //// constructor with two arguments/parameters
{

FirstName=FName;
Surname=SName;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, string SName, int age) //// constructor with three arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=age;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
void SetFullNames(char * FName, string SName)
{
FirstName = FName;
Surname = SName;
}
void SetAge(int age)
{
Age=age;
}
/////// -defined functions to initialize class attributes

char * GetFName()
{
return FirstName;
}
string GetSName()
{
return Surname;
}
int GetAge()
{
return Age;
}
int GetLevel()
{
return Level;
}
/////////////// -defined functions to return initialized class attributes
////////////// to the caller

void displayFullName()
{
cout<<GetFName()<<" "<<GetSName()<<endl;
}

void displayParameters()
{
cout<<GetFName()<<endl;
cout<<GetSName()<<endl;
cout<<GetAge()<<endl;
cout<<GetLevel()<<endl;
}

Date *GetDate()
{
return DOB;
}
};
int Student :: Level = 100; // Initialization of class variable









# include <iostream> // An header file for I/O operations
using namespace std; // For Uniqueness


class Person
{
class Student
{
class Date
{
int day;
char * month;
int year;
// class attributes: they are private by default

public:

void ManageDate(int d, char* M, int y) //// initialization of actual parameters
{
day=d;
month=M;
year= y;
}

Date() //default constructor
{
day=0;
month="";
year=0;
}

Date(int D, char* m, int Y)
{
day=D;
month=m;
year = Y;
}

int getDay()
{
return day;
}

int getYear()
{return year;
}

char * getMonth()
{
return month;
}
};


//////////// Class Attributes Starts from Here ////////////
char * FirstName; // Non-static variable
string Surname;
int Age;
static int Level; // A static variable
Date DOB; // An instance of class Date as an attribute of class Student

/////////////// Class Attributes Ends Here ///////////////
// The class attributes are public by default////////

public: //// change of access mode modifier from private to public

Student()
{

}
Student(int D, char* m, int Y):DOB(D,m,Y)
{
FirstName="";
Surname="";
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, Date D) //// constructor with one argument/parameter
{
FirstName=FName;
Surname="";
DOB=D;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, string SName,int D, char* m, int Y):DOB(D,m,Y) //// constructor with two arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, string SName, int age) //// constructor with two arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=age;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
void SetFullNames(char * FName, string SName)
{
FirstName = FName;
Surname = SName;
}
void SetAge(int age)
{
Age=age;
}
/////// -defined functions to initialize class attributes

char * GetFName()
{
return FirstName;
}
string GetSName()
{
return Surname;
}
int GetAge()
{
return Age;
}
int GetLevel()
{
return Level;
}
/////////////// -defined functions to return initialized class attributes
////////////// to the caller

void displayFullName()
{
cout<<GetFName()<<" "<<GetSName()<<endl;
}

void displayParameters()
{
cout<<GetFName()<<endl;
cout<<GetSName()<<endl;
cout<<GetAge()<<endl;
cout<<GetLevel()<<endl;
}

Date GetDate()
{
return DOB;
}
};
//////// end of class student
Student UniStudent;
string Address;

public:
Person(Student U, string add):UniStudent(U)
{
Address = add;
}

Person(char * FName, string SName,int D, char* m, int Y, string Add):UniStudent(FName, SName,(D,m,Y))
{
Address=Add;
}
string GetAddress(){return Address;}

Student GetStudent(){return UniStudent;}

void display()
{
UniStudent.displayParameters();
cout<<GetAddress()<<endl;
}
};

int Person::Student :: Level = 100; // Initialization of class variable



main()
{
Person person1("Bayo","Lawal",1,"April",89,"lagos"wink;
person1.display();
}












# include <iostream> // An header file for I/O operations
using namespace std; // For Uniqueness


class Person
{
class Student
{
class Date
{
int day;
char * month;
int year;
// class attributes: they are private by default

public:

void ManageDate(int d, char* M, int y) //// initialization of actual parameters
{
day=d;
month=M;
year= y;
}

Date() //default constructor
{
day=0;
month="";
year=0;
}

Date(int D, char* m, int Y)
{
day=D;
month=m;
year = Y;
}

int getDay()
{
return day;
}

int getYear()
{return year;
}

char * getMonth()
{
return month;
}
};


//////////// Class Attributes Starts from Here ////////////
char * FirstName; // Non-static variable
string Surname;
int Age;
static int Level; // A static variable
Date * DOB; // An instance of class Date as an attribute of class Student

/////////////// Class Attributes Ends Here ///////////////
// The class attributes are public by default////////

public: //// change of access mode modifier from private to public

Student()
{

}
Student(int D, char* m, int Y):DOB(new Date(D,m,Y))
{
FirstName="";
Surname="";
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, Date *D) //// constructor with one argument/parameter
{
FirstName=FName;
Surname="";
DOB=D;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, string SName,int D, char* m, int Y):DOB (new Date(D,m,Y)) //// constructor with two arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=0;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}

Student(char * FName, string SName, int age) //// constructor with two arguments/parameters
{
FirstName=FName;
Surname=SName;
Age=age;
Level = 150; /* This is an assignment statement for class variable Level
A class variable can be reassigned a value in the class
But the initialization must be done outside the class. */
}
void SetFullNames(char * FName, string SName)
{
FirstName = FName;
Surname = SName;
}
void SetAge(int age)
{
Age=age;
}
/////// -defined functions to initialize class attributes

char * GetFName()
{
return FirstName;
}
string GetSName()
{
return Surname;
}
int GetAge()
{
return Age;
}
int GetLevel()
{
return Level;
}
/////////////// -defined functions to return initialized class attributes
////////////// to the caller

void displayFullName()
{
cout<<GetFName()<<" "<<GetSName()<<endl;
}

void displayParameters()
{
cout<<GetFName()<<endl;
cout<<GetSName()<<endl;
cout<<GetAge()<<endl;
cout<<GetLevel()<<endl;
}

Date* GetDate()
{
return DOB;
}
};

Student * UniStudent;
string Address;

public:
Person(Student * U, string add):UniStudent(U)
{
Address = add;
}

Person(char * FName, string SName,int D, char* m, int Y, string Add):UniStudent (new Student(FName, SName,(D,m,Y)))
{
Address=Add;
}
string GetAddress(){return Address;}

Student * GetStudent(){return UniStudent;}

void display()
{
UniStudent->displayParameters();
cout<<GetAddress()<<endl;
}
};

int Person::Student :: Level = 100; // Initialization of class variable

whitebeard(m): 7:20pm On May 15, 2017
chai..!! do u want to kill yourself u are running c++ anyways try ing from YouTube..!!


my broda does this computer thing and when he starts in the morning it still evening before he stops..he has a lot of this video on his laptop and phone c++, java, python etc
bet9ja(m): 9:38pm On May 15, 2017
You don't post a text file if you need assistance, I will advice you to post the real code and go straight to your point.
Re: C++ Gurus: Urgent Help Needed. by Nobody: 10:16pm On May 15, 2017
1. Get Rid of the double quotes since you are using a char couldn't compile on GCC

I think i have an idea however I have no idea what dynamic instances mean in this context are they referring to Dynamic Object Allocation

anyway i think you should clarify but you can look at this to about Array of Pointers since they made mention of pointer attributes, after storing the instances you can write a method that takes an Array of pointers and deference's them.

The way the assignment is phrased seems confusing

Note: Not an Expert on C++ just know basic and enough to understand.

1 Like

kode12: 1:41am On May 16, 2017
bet9ja:
You don't post a text file if you need assistance, I will advice you to post the real code and go straight to your point.
Each code is about 200 lines thats the problem
Babaisaac(m): 6:59am On May 16, 2017
Pls Modify ur post
Babaisaac(m): 6:59am On May 16, 2017
Don't drop code this way if u need help, pls uncomment the code and post directly and then state what u want i.e ur question. I dint evn bother checking the code cux it's not put properly.
Re: C++ Gurus: Urgent Help Needed. by Nobody: 7:51am On May 16, 2017
I don't mind assisting but the question is kinda confusing for me, if anyone can explain it in properly I can write something, seems interesting
bet9ja(m): 7:23pm On May 16, 2017
Can you post the main problem maybe we can have an idea of what you are doing or trying to do, Those codes are spaghetti. They can discourage people who are interesting in learning programming.
Re: C++ Gurus: Urgent Help Needed. by Nobody: 7:50pm On May 16, 2017
am also battling with class in c++ .......guy i must cotinue tonight
uzoexcel(m): 8:23pm On May 16, 2017
The issue with posting code here directly is that some parenthesis changes to smiley faces.
stack1(m): 3:13am On May 21, 2017
NL isnt serious about programmers, else it should have solved issues with embedding code, all this while, and spambot sef, go dey act up atimes when posting code embarassed
Hibrahym: 9:48am On Jun 22, 2017

(1) (Reply)

Can Someone Help Out On How To Add A Database To My Windows Forms App

(Go Up)

Sections: How To . 44
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or s on Nairaland.