|
Please help me solve it ..... urgent....
4 header files that serve as the class
specification file to implement the aggregation, composition and inheritance concept
for the Employee, Name, Addres and ShiftSupervisor.
employee
- number : string
- hireDate : string
+ Employee() :
+ Employee(string, string, string)
+ setName(string) : void
+ setNumber(string) : void
+ setHireDate(string) : void
+ getName() : string
+ getNumber() : string
+ getHireDate() : string
Name
- firstName : string
- lastName : string
+ setFirstName(string) : void
+ setLastName(string) : void
+ getFullName() :
Address
- street : string
- city : string
- state : string
- postcode : string
- country : string
+ setStreet(string) : void
+ setCity(string) : void
+ setState(string) : void
+ setPostcode(string) : void
+ setCountry(string) : void
+ getFullAddress() :
Shift
- salary : int
- bonus : double
+ ShiftSupervisor() :
+ ShiftSupervisor(string, string,
string, double, double) :
+ setSalary(double) : void
+ setBonus(dlouble) : void
+ getSalary() : double
+ getBonus() : double
i stuck until here
#ifndef NAME_H
#define NAME_H
#include<string>
using namespace std;
class Name
{
private:
string FirstName;
string LastName;
public:
Name();
Name(string FN, string LN);
void setFirstName(const string FN) { FirstName = FN; }
string getFirstName() { return FirstName; }
void setLastName(const string LN) { LastName = LN; }
string getLastName() { return LastName; }
void setFullName(const string FN, const string LN);
string getFullName(){return FirstName,LastName;}
};
#endif
#ifndef ADDRESS_H
#define ADDRESS_H
#include<string>
using namespace std;
class Address
{
private:
string Street;
string City;
string State;
string Postcode;
string Country;
public:
Address();
Address(String str,string ct,string st,string pc,string ctry);
void setStreet(const string str) { Street = str; }
string getStreet() { return Street; }
void setCity(const string ct) { City = ct; }
string getCity() { return City; }
void setState(const string st) { Statet = st; }
string getState() { return State; }
void setPostcode(const string pc) { City = pc; }
string getPostcode() { return Postcode; }
void setCountry(const string ctry) { Country = ctry; }
string getCountry() { return Country; }
void setFullAdress(const string str, const string ct, const string st,const string pc
const string ctry);
string getFullAddress(){return Street, City, State, Postcode, Country};
};
#endif
#ifndef SHIFT_H
#define SHIFT_H
#include<cstring>
using namespace std;
class ShiftSupervisor
{
private:
double salary;
double bonus;
public:
ShiftSupervisor()
{ salary=0;
bonus=0;
}
ShiftSupervisor(char ,char ,char ,double salary,double bonus);
void setSalary(double);
void setBOnus(double);
double getSalary();
double getBonus();
};
#endif
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include<string>
#include"Name.h"
#include"Address.h"
#include"Shift.h"
using namespace std;
#endif
|
|
|
|
|
David9637 wrote: Please help me solve it ..... urgent....
First you must explain what the problem is, we cannot guess from you just dumping the complete assignment here. And secondly, saying it's urgent will not get it solved any faster.
|
|
|
|
|
Sorry that I'm still a beginner.Actually i have out of my mind continue write the header file. And i don't know the header is write correctly or not... Above is the task for my assignment. hopefully you can help me...
|
|
|
|
|
Sorry but you need to be much more specific, no one here is going to write your assignment for you.
|
|
|
|
|
Inheritance is a "is a" relationship between two objects. If A is a subtype of B then "A is a B". Every behaviour of objects of class B is exhibited by objects of class A (this is called the Liskov Substitution principle). In your model all ShiftSupervisors are also Employees so derive ShiftSupervisor from Employee.
Composition is a "has a" relationship between two objects. If A is composed of B then every instance of A has an instance of B with the same lifetime associated with it. By same lifetime I mean an object of class B springs into life every time an object of class A is created and the object of class B is destroyed when the object of class A is destroyed. In your example and Employee has a name so give each object of class Employee a data member of class.
Aggregation is a more general form of composition. It's essentially the same (a "has relationship") but with a different lifetime. In your example more than one Employee can share the same address so when an Employee object is destroyed the address they live at is not necessarily wiped off the map. Give each Employee object a reference to, pointer to or a shared pointer (preferably) an object of class Address.
And while I'm on the subject your Name and Address classes are an okay representation of their UML. There are way too many get/set member functions on each of them (how many houses are going to change their state, city of country?). And women don't "set their surnames" when they get married, they change_surname_to instead. And you really don't need default constructors on them either, even if want to use the type in a collection class.
You want to define Employee next and when you've done that ShiftSupervisor. Have a crack at both and if you're having trouble we can look at the definitions and perhaps drop a few hints as to how to proceed.
modified 9-Jun-12 16:22pm.
|
|
|
|
|
I build the following code(copy from MSDN 2008 SP1)
#include <random>
#include <iostream>
typedef std::tr1::minstd_rand Myeng;
typedef std::tr1::mersenne_twister<unsigned int, 32, 624,
397, 31, 0x9908b0df, 11, 7, 0x9d2c5680,
15, 0xefc60000, 18> Myceng; int main()
{
Myeng eng;
Myceng ceng;
Myceng::result_type compval = ceng();
compval = compval;
std::cout << "W == " << Myceng::word_size << std::endl;
std::cout << "N == " << Myceng::state_size << std::endl;
std::cout << "M == " << Myceng::shift_size << std::endl;
std::cout << "R == " << Myceng::mask_bits << std::endl;
std::cout << "A == " << Myceng::parameter_a << std::endl;
std::cout << "U == " << Myceng::output_u << std::endl;
std::cout << "S == " << Myceng::output_s << std::endl;
std::cout << "B == " << Myceng::output_b << std::endl;
std::cout << "T == " << Myceng::output_t << std::endl;
std::cout << "C == " << Myceng::output_c << std::endl;
std::cout << "L == " << Myceng::output_l << std::endl;
std::cout << "min == " << ceng.min() << std::endl;
std::cout << "max == " << ceng.max() << std::endl;
ceng.seed(); std::cout << "a random value == " << ceng() << std::endl;
std::cout << "a random value == " << ceng() << std::endl;
std::cout << "a random value == " << ceng() << std::endl;
Myceng ceng2(eng); ceng2.seed(eng);
Myceng ceng3(5UL); ceng3.seed(5UL);
return (0);
}
with Visual Studio 2010, but the compiler reports errors:
1>------ Build started: Project: Console, Configuration: Debug Win32 ------
1>Build started 2012-6-9 11:05:53.
1>InitializeBuildStatus:
1> Touching "Debug\Console.unsuccessfulbuild".
1>ClCompile:
1> Console.cpp
1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1>z:\e\disk\vc\justtest\console\console.cpp(27): warning C4003: not enough actual parameters for macro 'min'
1>z:\e\disk\vc\justtest\console\console.cpp(27): error C2059: syntax error : '('
1>z:\e\disk\vc\justtest\console\console.cpp(28): error C2039: '<<' : is not a member of 'std::tr1::mersenne_twister<_Ty,_Wx,_Nx,_Mx,_Rx,_Px,_Ux,_Sx,_Bx,_Tx,_Cx,_Lx>'
1> with
1> [
1> _Ty=unsigned int,
1> _Wx=32,
1> _Nx=624,
1> _Mx=397,
1> _Rx=31,
1> _Px=-1727483681,
1> _Ux=11,
1> _Sx=7,
1> _Bx=-1658038656,
1> _Tx=15,
1> _Cx=-272236544,
1> _Lx=18
1> ]
1>z:\e\disk\vc\justtest\console\console.cpp(28): error C2039: 'ceng' : is not a member of 'std::tr1::mersenne_twister<_Ty,_Wx,_Nx,_Mx,_Rx,_Px,_Ux,_Sx,_Bx,_Tx,_Cx,_Lx>'
1> with
1> [
1> _Ty=unsigned int,
1> _Wx=32,
1> _Nx=624,
1> _Mx=397,
1> _Rx=31,
1> _Px=-1727483681,
1> _Ux=11,
1> _Sx=7,
1> _Bx=-1658038656,
1> _Tx=15,
1> _Cx=-272236544,
1> _Lx=18
1> ]
1>z:\e\disk\vc\justtest\console\console.cpp(28): warning C4003: not enough actual parameters for macro 'max'
1>z:\e\disk\vc\justtest\console\console.cpp(28): error C2059: syntax error : '('
1>z:\e\disk\vc\justtest\console\console.cpp(30): error C2039: 'ceng' : is not a member of 'std::tr1::mersenne_twister<_Ty,_Wx,_Nx,_Mx,_Rx,_Px,_Ux,_Sx,_Bx,_Tx,_Cx,_Lx>'
1> with
1> [
1> _Ty=unsigned int,
1> _Wx=32,
1> _Nx=624,
1> _Mx=397,
1> _Rx=31,
1> _Px=-1727483681,
1> _Ux=11,
1> _Sx=7,
1> _Bx=-1658038656,
1> _Tx=15,
1> _Cx=-272236544,
1> _Lx=18
1> ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:04.00
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
Any one can help?
|
|
|
|
|
I am guessing that line 27/28 are:
std::cout << "min == " << ceng.min() << std::endl;
std::cout << "max == " << ceng.max() << std::endl;
and that both functions require arguments.
|
|
|
|
|
Yes, you are right.
But the two functions need no parameters.
They are the member functions of
mersenne_twister<unsigned int, 32, 624,
397, 31, 0x9908b0df, 11, 7, 0x9d2c5680,
15, 0xefc60000, 18>
I don't know why I get these erros.
|
|
|
|
|
I just copied this sample from MSDN[^] and built it without problems in Visual C++ 2010 Express. Just to verify I copied the code from your original question and that also builds correctly. The only issue I can see is:
1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)1
which may mean that the Windows version is incorrect.
|
|
|
|
|
Thank you for you quick reply.
I found the reason by your hint:
I add so many headers into my source file.
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <ctime>
#include <cstring>
#include <afx.h>
#include <set>
#include <hash_map>
#include <hash_set>
#include <locale>
#include <sstream>
#include <codecvt>
#include <cstring>
#include <string>
#include <clocale>
#include <random>
#include <Winsock2.h>
#include "dba.h"
using namespace std;
When I comment out the unnecessary headers from my source file. I compile successly, too!!
Thank you very much!!!
|
|
|
|
|
The error I'll focus on is:
1>z:\e\disk\vc\justtest\console\console.cpp(27): warning C4003: not enough actual parameters for macro 'min'
The line in question is:
std::cout << "min == " << ceng.min() << std::endl;
Notice the error is complaining about a macro called 'min' and keep in mind the fact that macro processing happens before compilation and doesn't respect normal language conventions such as scope, member functions, namespaces, etc.
The min at line 27 was being treated as a macro and object 'ceng' doesn't enter into the issue.
You obviously nuked the include that was defining the macro.
Putting something like this after all the includes would also fix the problem:
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
Steve
|
|
|
|
|
If CDialog is destroyed is UI CWinThread created While object was alive get destroyed as Well
If answer is yes then I understand my problem
|
|
|
|
|
If the CDialog you're talking about is the main dialog, then when the dialog exits, the application exits and then all the threads be it worker threads or UI threads are all destroyed.
|
|
|
|
|
Being a Mainframe assembler programmer I experinced the same thing on MVS Z/OS opertaing system
I did a ATTACH to start a thread subtask loaded programs obtained storage and as soon as the task thread goes away MVS reclaims all resources obtained by the TASK/THREAD
My question is if I do ::ShowWindow what does SW_HIDE do; are the resources used with the Cwnd:: derived object still in memory
thanks
|
|
|
|
|
Hide does not destroy the window and so all resources are still loaded in memory.
In fact, the FindWindow API will still find this hidden window.
|
|
|
|
|
Generally... no... remember that the concepts are not really tied together. For example, you can have a CWinThread with no CDialog, and you can have multiple CDialogs in one CWinThread.
|
|
|
|
|
Hi,
I have a CFormView derived class named CCatalogView. The Dialog Form was designed using the VS2008 resource editor.
I also created a new method inside the CCatalogView like the follow :
CWnd* CCatalogView::CreatePane(CWnd* pParentWnd)
{
if (GetSafeHwnd() == 0){
VERIFY(Create(_T("CatalogView"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CXTPEmptyRect(), pParentWnd, NULL, 0));
}
return this;
}
While I can show the content of this FormView inside a pane, when I exit from the application I get a memory error :
===================================
Windows has triggered a breakpoint in Test.exe.
This may be due to a corruption of the heap, which indicates a bug in Test.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Test.exe has focus.
The output window may have more diagnostic information.
====================================
I have already found a solution, and that was to use the
create method, outside of the class CCatalogView as with the following code :
m_pFormFrame = new CFrameWnd;
CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CCatalogView);
context.m_pCurrentDoc = NULL;
m_pFormFrame->Create(NULL, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, NULL, 0, &context);
m_pFormFrame->SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
pPane->Attach(m_pFormFrame);
Now the question is : Why the 1st part of the code corrupts the heap ? I suspect the the "Create" is constructed to the heap instead of the stack that I assume.
If that is true, can I modify the code to make it work ?
Best Regards,
sdancer75
|
|
|
|
|
I can recommend using Application Verifier[^] and then run your application within a debugger. Then it should break the application at the initial corruption of the heap.
Application Verifier is part of the Windows SDK[^]
|
|
|
|
|
Yep, verifier, it is a good tool.
==============================
Nothing to say.
|
|
|
|
|
Thanks,
I didn't used Application Verifier before.
Does it run under the VS2008 IDE ?
Regards,
sdancer75
|
|
|
|
|
You're calling two completely different functions! In the first example you're calling CCatalogView::Create, in the second you're calling CFrameWnd::Create.
As to why it's failing.. I can't tell exactly but one idea is that you're creating the CCatalogView as an automatic object. When you call CreatePane a WIN32 window object is created. When the pane window (as in the WIN32 window) is destroyed it tells the CCatalogView to do a delete this; . As the C++ object is on the stack delete goes a bit haywire.
In the second case everything's allocated on the heap. You CCatalogView is implicitly created on the heap by CFrameWnd::Create. When the WIN32 window objects are destroyed the delete this; works the way it should do and everything's cool.
Just out of interest all this delete this; rubbish generally happens in whatever override of CWnd::PostNCDestroy gets called. As a general rule always create MFC C++ window objects on the heap, unless it's a modal dialogue when it's safe to create it on the stack.
|
|
|
|
|
Thank you for your reply.
I am not sure if this is the real problem.... I will search more about this.
Regards,
sdancer75
|
|
|
|
|
As you can see "Call Stack" stops at _CrtIsValidHeapPointer. It seems that is trying to free the CCatalogView Object but it fails. Maybe that means that somehow the CCatalogView class has alreaded deleted from the memory. What is your opinion ?
ntdll.dll!77470724()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!7743295a()
ntdll.dll!77401997()
KernelBase.dll!760d4bf9()
> Gnosis.exe!_CrtIsValidHeapPointer(const void * pUserData=0x03387e2c) Line 2103 C++
Gnosis.exe!_free_dbg_nolock(void * pUserData=0x03387e2c, int nBlockUse=12582916) Line 1317 + 0x9 bytes C++
Gnosis.exe!_free_dbg(void * pUserData=0x03387e2c, int nBlockUse=12582916) Line 1258 + 0xd bytes C++
Gnosis.exe!CObject::operator delete(void * p=0x03387e2c) Line 42 + 0xe bytes C++
Gnosis.exe!CCatalogView::`scalar deleting destructor'() + 0x3c bytes C++
Gnosis.exe!CView::PostNcDestroy() Line 121 + 0x21 bytes C++
Gnosis.exe!CWnd::OnNcDestroy() Line 864 C++
Gnosis.exe!CWnd::OnWndMsg(unsigned int message=130, unsigned int wParam=0, long lParam=0, long * pResult=0x0018e038) Line 2042 C++
Gnosis.exe!CWnd::WindowProc(unsigned int message=130, unsigned int wParam=0, long lParam=0) Line 1755 + 0x20 bytes C++
Gnosis.exe!AfxCallWndProc(CWnd * pWnd=0x03387e2c, HWND__ * hWnd=0x001906d6, unsigned int nMsg=130, unsigned int wParam=0, long lParam=0) Line 240 + 0x1c bytes C++
Gnosis.exe!AfxWndProc(HWND__ * hWnd=0x001906d6, unsigned int nMsg=130, unsigned int wParam=0, long lParam=0) Line 403 C++
user32.dll!76126238()
user32.dll!76127298()
user32.dll!76126899()
user32.dll!76127177()
user32.dll!76131e3a()
ntdll.dll!773b00e6()
user32.dll!76131e83()
Gnosis.exe!CWnd::DestroyWindow() Line 1007 + 0xd bytes C++
b60f0004()
sdancer75
|
|
|
|
|
Either you've stuck the CCatalogView on the stack and PostNcDestroy is trying to delete it when the WIN32 window is being deleted OR you're stashing a pointer to the CCatalogView some where and deleting it. It may be hidden if you've stored it as a pointer to one of it's parent classes.
|
|
|
|
|
Thank you Aescleal,
Yes the CCatalogView is created on the stack and I did know that from the beggining, but I was wondering about the time are happenning all these things.
1. I create on the stack the CCatalogView
2. Inside the CCatalogView class I create a Win32 Window (using Create). Really, does this window is created on the heap or in the stack ? I assume that is created on the stack. Anyway, I tried to explicitly create this window on the heap, using new (on the CreatePane) & delete (on the destructor) functions but it also fails.
3. Now, according to my assumptions that both objects are in the stack, at the exiting procedure, it disposes first the last inserted item which is the Win32 Window (as I mentioned, I assume it created on the stack) and then the CCatalogView class itleft.
What's of the above assumptions are wrong ? That is what I did not understand.
Regards,
George
PS: Reading your comment again, you assume that the MFC Framework when is trying to delete the Window itself, is deleting also the class that is associated with that window. Maybe, is something that I did not understand well. Can you please clarify that ?
sdancer75
|
|
|
|
|