473,671 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

intermediate/beginner question on classes

I am coding for a large company and I have a block of code in front of
me that looks like the below, but with names changed for
confidentiality reasons.

SomeFunction(St udentClass Mary, StudentClass Jill, StudentClass Vijay)
// In reality there are about a dozen variable names

if (Mary.HasProble m() || Jill.HasProblem () || Vijay.HasProble m() )
// and on and on

{ return StudentClass("A student has a problem");}

So I'm changing it to

if(Mary.HasProb lem()) returnStudentCl ass("Mary has a problem.");
if(Jill.HasProb lem()) returnStudentCl ass("Jill has a problem.");
if(Vijay.HasPro blem()) returnStudentCl ass("Vijay has a problem.");

// many more similar statements.

I'm doing this to get more accurate diagnostic messages.

What is a more compact way of doing the above?

Thanks a lot for your help.

Paul Epstein

Jul 24 '07 #1
1 1473
On 2007-07-24 10:36, pa**********@at t.net wrote:
I am coding for a large company and I have a block of code in front of
me that looks like the below, but with names changed for
confidentiality reasons.

SomeFunction(St udentClass Mary, StudentClass Jill, StudentClass Vijay)
// In reality there are about a dozen variable names

if (Mary.HasProble m() || Jill.HasProblem () || Vijay.HasProble m() )
// and on and on

{ return StudentClass("A student has a problem");}

So I'm changing it to

if(Mary.HasProb lem()) returnStudentCl ass("Mary has a problem.");
if(Jill.HasProb lem()) returnStudentCl ass("Jill has a problem.");
if(Vijay.HasPro blem()) returnStudentCl ass("Vijay has a problem.");

// many more similar statements.

I'm doing this to get more accurate diagnostic messages.

What is a more compact way of doing the above?
Probably not they way you are doing, what if more than one student have
a problem? Personally I find it quite dubious to return a StudentClass
object if a student have a problem, perhaps throw an exception instead?

The place where you should change the code is not in SomeFunction(), but
in the code that calls, it. If SomeFunction() returns with the status
that a student has problems you should then loop through the students
and check their status and print the names of those with problems.

By the way, it might be better to pass a collection of students (such as
vector or list) instead of passing each student.

--
Erik Wikström
Jul 24 '07 #2

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

Similar topics

16
2199
by: Rod Carrol | last post by:
Hello all, As a beginner I've been exeperiencing lots of errors while building my website, (I'm currently attempting to implement a member login/registration piece for my site using mySQL and PHP) I've read that PHP is secure in that it hides lots of code from hackers and people trying to snoop around on the web site running the PHP scripts - however, one thing I've noticed is that whenever I get a script error, (for example, failure...
2
5476
by: jklimek | last post by:
In May of this year I graduated from Penn State with a BS in IST (Information Sciences and Technology). Right after graduation I got a database programming job with a company that uses Delphi 6 and MS SQL Server 2000. I've been working with this company for six months now but I'm still not very good with SQL. I can do basic SQL queries and table joins (as well as use datetime functions and cursors), but I'd say I'm only at an...
15
1921
by: PhilB | last post by:
Hello experts, I am a complete beginner in C++ (although I know C). I am trying to compile the code below, and I get the following error. Can anyone explain to me my mistake? Thanks! PhilB myprog2.cpp: In method `Line::Line (Point, Point)': myprog2.cpp:32: no matching function for call to `Point::Point ()'
3
1545
by: pestul | last post by:
I'm quite new with Access so please bare with me. I'm pretty sure what I'm looking for will require the integration with VB to function properly. Here's what I have: Portfolios for inviduals who have taken part in courses at this department. Information includes: Name (First/Last)
8
1451
by: ^MisterJingo^ | last post by:
Hi all, I have a question regarding inheritance. I'll use the following code for an example (its been stripped down to the minimum): // code start using System; class Animal {
4
1680
by: Chris | last post by:
Hi all, I can serialize and deserialize a single class, but I'm wondering if it's possible to serialize/deserialize different class types in the same file? For example, I have a base class, and 3 classes derived from it. Instances of these 3 classes are stored in a List<baseclass>. I'd like to be able to save the objects in List<>, and later reload them. Is this possible? I can write each object to the same file by using a different...
4
2658
by: Johs | last post by:
I am looking for a good C++ book for beginners. I have some experience with C and a lot of experience with Java. I am currently reading Bjarne Stroustrups C++ Programming Language but it starts off rather complex without examples of compiling modules or making and using classes. Is there some C++ books that takes you through the whole process of making modules, compiling them and using classes?
9
2225
by: Daniel | last post by:
Looking to see if anyone can offer some suggestions on some good VB.net books? looking for beginner to intermidiate and to expert.. Any suggestions? -- ASP, SQL2005, DW8 VBScript
2
201
by: Daniel | last post by:
Looking for a good resource for beginners? books, online anything that will get me started.. what im trying to focus on is building a small program in c# to look thru a few files in a folder that contain certain words / messages ( i know that is probably more than a beginner can do right off the bat ) but i have other programmers available that can help, but rather try myself before i get them involved.. example of what i mean
22
18134
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
8483
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
8402
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
8825
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
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
6237
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
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2819
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
2062
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.