Solved

OOPS Question

Posted on 2007-11-28
3
333 Views
Last Modified: 2013-12-14
Hi Experts,
            This may be a walk in the park for many of you. I wanted to know how efficiently Object Oriented concepts can be used to the following requirement.
Problem
As a part of a larger system, a class
    Archive
is required that will accept whole number parameters to a method called
    Add
which collects the number for later use. The class Archive should also provide a method
    Show
that displays the collection of numbers on the standard console output.  Object Oriented Concepts and attention to detail should be demonstrated by the Class.

Even though the solution is a basic one, I want you to give attention to every detail and exhibit the possible Object Oriented Concepts giving attention to all the details.

Thank you very much in advance,
Curtis.
0
Comment
Question by:dinedine
  • 2
3 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20367967
Hi dinedine,

Object oriented programming is often much more efficient that it first appears.  To understand this, it helps to think of what OOP actually is from a programming viewpoint.  In C++, what you're proposing could easily look something like this:

Class myclass
{
};

myclass *MyObject;

  MyObject = new myclass;

  MyObject->Add (1);


Programming the identical functionality in conventional C could easily look like this:

typedef struct
{
} mystruct

mystruct *MyObject;

  MyObject = (mystruct *)malloc (sizeof (mystruct));
  Add (MyObject, 2);



In essence, they are the same, as the Add() method in the first example implicitly passes the 'this' pointer.  At the assembly level, both Add() implementations deal with the same number of parameters so sill produce very, very similar object code.


Good Luck,
Kent
0
 

Author Comment

by:dinedine
ID: 20368967
Hey,
        I got your viewpoint. But, whats going on in my mind is, i don't want to miss any details in the given requirement....  Here's the problem again.....

" As a part of a larger system, a class "Archive" is required that will accept whole number parameters to a method called "Add" which collects the number for later use. The class "Archive" should also provide a method "Show" that displays the collection of numbers on the standard console output. Object Oriented Concepts and attention to detail should be demonstrated by the Class. "

For example, its given that,  " As a part of a larger system ". Does that need to be reflect a change in the implementation. or what else is main in this trivial question.

Reply me if something rings a bell.

Thank you so much for your time and consideration Kent
Curtis
0
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 20369143
Hi Kdo,

Sorry.  I thought you were asking how efficient it would be when written as OOP instead of a more traditional approach.

Most C++ libraries have their own collection or list classes.  You may want to use one of them or write your own.  And extending one of the classes may fit best.  Still, here's a foundation for what you'll probably want.


The Add() method does all of the heavy lifting.  Before coding it, you'll need to make some decisions.  Do you store duplicate values?  Do you want the list sorted?  etc.  Depending on your answers you may be able to use the std::vector class to store the integers.

If not, use a variant of the class in the example.  When you need to insert a value into the list, check to make sure that the array is not full.  If it is full, double its size (copying the old list to the new one), and continue.


Good Luck,
Kent

class TArchive
{
  private:
    int *List;
    int Count;
    int Limit; 
  public:
    TArchive ();
    ~TArchive ();
    Add ();
    List;
}; 
TArchive::TArchive ()
{
  Count = 0;
  Limit = 1000;
  List = new int [Limit];
} 
TArchive::~TArchive ()
{
  delete [] List;
} 
TArchive::Add (int NewValue)
{
} 
TArchive::List ()
{
}

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deletiā€¦
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question