Solved

OOPS Question

Posted on 2007-11-28
3
329 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:Kdo
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:
Kdo 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now