473,404 Members | 2,179 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,404 software developers and data experts.

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(StudentClass Mary, StudentClass Jill, StudentClass Vijay)
// In reality there are about a dozen variable names

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

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

So I'm changing it to

if(Mary.HasProblem()) returnStudentClass("Mary has a problem.");
if(Jill.HasProblem()) returnStudentClass("Jill has a problem.");
if(Vijay.HasProblem()) returnStudentClass("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 1459
On 2007-07-24 10:36, pa**********@att.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(StudentClass Mary, StudentClass Jill, StudentClass Vijay)
// In reality there are about a dozen variable names

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

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

So I'm changing it to

if(Mary.HasProblem()) returnStudentClass("Mary has a problem.");
if(Jill.HasProblem()) returnStudentClass("Jill has a problem.");
if(Vijay.HasProblem()) returnStudentClass("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
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...
2
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...
15
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 ...
3
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...
8
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
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...
4
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...
9
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
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...
22
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.