473,715 Members | 5,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 TenseignantErro r{} ; // 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 horaireHebdomad aire (int numSem) const ;

/*

Create a new hours schedule by fusionning both schedule, throw an exception
of class TenseignantErro r 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 (TenseignantErr or,
Toverflow) ;

Void printLn() ;

Private :

Char m_nomEnseignant [30] ; // obligatory

Tcase* m_cases[CcasesMax] ;

Int m_nbCases ;

} ;

#endif

The questions:

1) Does the method Thoraire::charg eHoraire() 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::opera tor+(const Thoraire& hor) ?

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

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 1186
stephane wrote:
1) Does the method Thoraire::charg eHoraire() 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::opera tor+(const Thoraire& hor) ?
TenseignantErro r 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::charg eHoraire()?
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****@digital raid.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****@digital raid.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
2390
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 me. This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text. I have done Exercise 7 for you: Below you will find the ADT specification for a string of characters. It represents slightly more that a minimal string...
10
2050
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
1636
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 programming well i have been for about 8 years... My brother graduated last year from UCR majoring Computer science and he now works for a buisness programming... well anyways i want to start programming, my brother gave me a c++ book he used but i...
3
1533
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 menu and report page. Tomorrow to the 8 a.m. i must do this, but i don't know how.... Can someone help me? There are few messageboxes for help. Here is my code (it's vbs):
3
1745
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 asp.net web matrix. My problem is the following: in the book it talks about connectiong to the PUBS database and i know sql programming and have worked with sql server but i dont see the pubs database
6
1820
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 this objects : - DATASET - sqlDataAdapter - BindingSource - sqlConnection I usually write database applications in Delphi, but now I want to learn Dot Net platform ant it's quite diffrent than programming
10
2027
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 because the program compiles with just one parameter. Can someone look at this and tell me where I made my error? This is the error I get while trying to compile. error C2664: 'GradeBook::GradeBook(const GradeBook &)' : cannot convert...
5
3370
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 I could better understand the concept, he was trying to convey to me. I ran my own example and it crashed and burn "what a surprise!" : (. I ran the authors example out of the book and quess what, it crashed also, : 0. I ran them both on my...
0
5571
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
5
1798
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. Assume that the bar code is to access a file that store the product descriptions, unit price and quantity of each product sold in the shop. Assume that there are only 10 products in
0
8821
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9340
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.