473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

help please / object programming

I am preparing an exam and I have a copy of last year exam.

I answered the first questions and I wander if I am right or wrong. Can
someone have a look at the questions and at my answers please?

There is no code to write just general questions about the two class'.

the code:

/--

# ifndef CASE_H

# define CASE_H

#include <iostream>

#include <iomanip>

#include <cstring>

using namespace std ;

const int Clundi = 1 ;

const int Cmardi = 2 ;

const int Cmercredi = 3 ;

const int Cjeudi = 4 ;

const int Cvendredi = 5 ;

const int Csamedi = 6 ;

const int Cdimanche = 7 ;

class Tcase{

public :

Tcase (int numSemaine, int numJour, double heureDebut, double duree,

char matiere[], char classe[]= " ", char salle[]= " ") ;

int getNumSemaine() const ;

double getDuree() const ;

void printLn() const ;

private :

//attributs obligatoires

int m_numSemaine ; //1..53

int m_numJour ; //1..7

double m_heureDebut ; //13h30 = 13.5

double m_duree ; //2h45 = 2.75

char m_matiere[10] ; //p ex. prog7

//attributs optionnels

char m_classe[10] ; //p. ex. 3IG-EE

char m_salle[10] ; //p. ex A46A

}

#endif



# ifndef HORAIRE_H

# define HORAIRE_H

# include <iostream>

# include <cstring>

using namespace std ;

#include « case.h »

class TenseignantError{} ; // the teacher is not matching

class Toverflow{} ; //capacity overflow



const int CcasesMax = 1000 ;

class Thoraire{

public :

//create a new hours schedule

Thoraire (const char nomEnseignant[]) ;

//add a case in the hours schedule

void ajouteCase (Tcase* caseHor) throw (Toverflow) ;

//calculate the total hours

double chargeHoraire() const ;

//return a sample of the schedule



//return an empty schedule if the number of the week doesn't
exist

Thoraire horaireHebdomadaire (int numSem) const ;

/*

Create a new hours schedule by fusionning both schedule, throw an exception
of class TenseignantError when the schedules don't have the same teacher
(enseignant) name.

Throw an exception of class Toverflow when the fusion create an overflow of
capacity (>CcasesMax)

*/

Thoraire operator+ (const Thoraire & hor) const throw (TenseignantError,
Toverflow) ;

Void printLn() ;

Private :

Char m_nomEnseignant [30] ; // obligatory

Tcase* m_cases[CcasesMax] ;

Int m_nbCases ;

} ;

#endif

The questions:

1) Does the method Thoraire::chargeHoraire() have the right to access the
member m_duree of the class Tcase?

2) Does the method Tcase::printLn() have the right to access the member
m_heureDebut of the class Tcase?

3) What are the exceptions that can be thrown by the method Thoraire
Thoraire::operator+(const Thoraire& hor) ?

4) What are the exceptions that can be thrown by the method double
Thoraire::chargeHoraire()?

5) What's the technical reason that forces the developper of the class
Thoraire to declare an array of Tcase pointers as member of the class
instead of an array of Tcase?

Answers according to me:

1) No because it's trying to access the private part of another class.

2) Yes because the method belongs to the same class.

3) when "enseignant" is not matching and when the name of "enseignant" is
not the same.

4) none ? ( I am not sure of this at all)

5) to avoid creating an object which would be infinite. Because it would be
a recursive creation of the objet. meaning an object created in an object
that crate another object and on and on.

thanks for your help!
Jul 23 '05 #1
6 1163
stephane wrote:
1) Does the method Thoraire::chargeHoraire() have the right to access the
member m_duree of the class Tcase?
Not directly, but you can get its value by calling the getter. I guess
your prof will probably want to hear what you said: No, because it's a
private member and an implementation detail.
2) Does the method Tcase::printLn() have the right to access the member
m_heureDebut of the class Tcase?
Sure. They both belong to the same class.
3) What are the exceptions that can be thrown by the method Thoraire
Thoraire::operator+(const Thoraire& hor) ?
TenseignantError and Toverflow. If it throws an exception which is not
in this list, your program will call unexpected() and terminate (if you
don't override this handler and do something more appropriate).
4) What are the exceptions that can be thrown by the method double
Thoraire::chargeHoraire()?
All exceptions imaginable. If it wouldn't be allowed to throw any
exceptions, it would have to be declared using 'throw ()'. If it is
declared without specifying which exceptions it will throw, it may throw
any kind of exception.
5) What's the technical reason that forces the developper of the class
Thoraire to declare an array of Tcase pointers as member of the class
instead of an array of Tcase?


I can't see immediately why this is needed. Maybe someone else can
answer this. I also read your answer, but I'm not sure what you mean
with recursive creation. It's just an array of objects. Nothing
recursive there.

--
Regards,
Matthias
Jul 23 '05 #2

Matthias wrote:
stephane wrote:
5) What's the technical reason that forces the developper of the class Thoraire to declare an array of Tcase pointers as member of the class instead of an array of Tcase?


I can't see immediately why this is needed. Maybe someone else can
answer this. I also read your answer, but I'm not sure what you mean
with recursive creation. It's just an array of objects. Nothing
recursive there.

--
Regards,
Matthias

Probably because it doesn't have a default constructor?

-shez-

Jul 23 '05 #3
shez wrote:
Matthias wrote:
stephane wrote:
5) What's the technical reason that forces the developper of the
class
Thoraire to declare an array of Tcase pointers as member of the
class
instead of an array of Tcase?


I can't see immediately why this is needed. Maybe someone else can
answer this. I also read your answer, but I'm not sure what you mean
with recursive creation. It's just an array of objects. Nothing
recursive there.

--
Regards,
Matthias


Probably because it doesn't have a default constructor?

-shez-


Yes. It was already at the tip of my tongue... ;-)

--
Regards,
Matthias
Jul 23 '05 #4
What would have been the difference if it had a default constructor?

"Matthias" <no****@digitalraid.com> a écrit dans le message de news:
ct*************@news.t-online.com...
shez wrote:
Matthias wrote:
stephane wrote:

5) What's the technical reason that forces the developper of the


class
Thoraire to declare an array of Tcase pointers as member of the


class
instead of an array of Tcase?

I can't see immediately why this is needed. Maybe someone else can
answer this. I also read your answer, but I'm not sure what you mean
with recursive creation. It's just an array of objects. Nothing
recursive there.

--
Regards,
Matthias


Probably because it doesn't have a default constructor?

-shez-


Yes. It was already at the tip of my tongue... ;-)

--
Regards,
Matthias

Jul 23 '05 #5
Stephane Vollet wrote:
What would have been the difference if it had a default constructor?


The problem is, if it doesn't, how should the compiler know how to
construct e.g. 10 Tcase objects in an array?

Tcase array[10];

It is obvious here that the default constructor of the 10 Tcase objects
has to be called. However, you didn't define one. In other words,
you have no chance here to pass the arguments to the constructor defined
by Tcase. That is illegal, you can't just omit them. However, if you
hold Tcase pointers instead:

Tcase* array[10];

In this case you *don't* directly construct 10 Tcase object, but are
only storing pointers to possible Tcase objects. Now you can do this in
some init function of your program:

for( int i=0; i<10; ++i )
{
array[i] = new Tcase(a,b,c,...); // call ctor with mandatory args
}

--
Regards,
Matthias
Jul 23 '05 #6
"Stephane Vollet" writes:
What would have been the difference if it had a default constructor?

"Matthias" <no****@digitalraid.com> a écrit dans le message de news:
ct*************@news.t-online.com...
shez wrote:
> Matthias wrote:
>
>>stephane wrote:
>>
>>>5) What's the technical reason that forces the developper of the
>
> class
>
>>>Thoraire to declare an array of Tcase pointers as member of the
>
> class
>
>>>instead of an array of Tcase?
>>
>>I can't see immediately why this is needed. Maybe someone else can
>>answer this. I also read your answer, but I'm not sure what you mean
>>with recursive creation. It's just an array of objects. Nothing
>>recursive there.
>>
>>--
>>Regards,
>>Matthias
>
> Probably because it doesn't have a default constructor?
>
> -shez-
>


Yes. It was already at the tip of my tongue... ;-)


One of the rules is that there must be a default constructor to create an
array of objects. If you don't like the initializing that results, use a
function that initializes each object to your taste. You would probably
call the initializer with a for loop.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
10
by: Robert | last post by:
Where can i find a free web- based VC++ course? (also i've to dowanload it) I'm interested also in VB and C++ thanks, Robert
4
by: Weasel | last post by:
Hey everyone, My names John and i just recently joined this googl group, and I joined because i need some help. I'm currently a Sophomore in High school and i'm really interested in computer...
3
by: Marek | last post by:
Hello gurus! I wrote a code in VBS, that will check, that current user is in one from three groups. But i don't know how asimilate it with asp.net. This page will be a bridge between 2 - main...
3
by: ntexchange05 | last post by:
I am trying to learn asp.net and build a site and i am using web matrix and vb.net. I have installed the MSDE on my windows xp pro, i am using the book calledbeginning dynamic websites with...
6
by: lennon1 | last post by:
Hi, I have already started learning .NET and I have a question. If I want to do anything - Display Data, Navigate, Update - with database (SQL Server) in Visual Studio 2005, do I have to use all...
10
by: B Williams | last post by:
I have been working with this code for a better part of the day and I can't figure out where I am making a mistake. I can only imagine it is when I declare multiple paramaters on the constructor...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: alck1234 | last post by:
Hi, I need help on my mini project on object orientated programming. The question goes like this: A mini-mart has just installed a bar code reader to improve efficiency at their checkouts....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.