Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 26th, 2006, 6:25 PM   #1
Mack1982
Programmer
 
Join Date: Dec 2004
Posts: 34
Rep Power: 0 Mack1982 is on a distinguished road
Unhappy Problem with "Information Hiding"

I have been trying to compile a code using the information hiding method but am unsuccessful. I am using the BORLAND Compiler Version 5.02.
The Code that I am trying to compile could be found here:

http://web.cs.gc.cuny.edu/~armanartuc/4100/notes11.html
It is the professor code, so i don't think the problem is with the code.

I have copy and pasted this file and have given them propriate names, and placed them all in a single folder in C drive called program.
Then loaded the TEST.CPP file in BORLAND and pressed the compile button, but it didnot work.

Can anyone tell me what am i doing wrong?
regards
Mack1982
Mack1982 is offline   Reply With Quote
Old Apr 26th, 2006, 6:33 PM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
1 - Cut and paste the exact code you're trying to compile into your post (use [code] tags)
2 - Post the errors you're getting

Hopefully then, someone will be able to help you.
OpenLoop is offline   Reply With Quote
Old Apr 26th, 2006, 6:45 PM   #3
Mack1982
Programmer
 
Join Date: Dec 2004
Posts: 34
Rep Power: 0 Mack1982 is on a distinguished road
Code TAG??
LIKE
for start [code]
FOR END [\CODE]
Mack1982 is offline   Reply With Quote
Old Apr 26th, 2006, 7:00 PM   #4
Mack1982
Programmer
 
Join Date: Dec 2004
Posts: 34
Rep Power: 0 Mack1982 is on a distinguished road
All files saved in C:\Mansoor\College\CIS 4100\

the header file saved as "listType.h"

class listType
{
public:
    bool isEmptyList() const;
    // returns true if the list is empty (length=0)
    // returns false if the list is not empty

    bool isFullList() const;
    // returns true if the list is filled up (length=1000)
    // returns false if the list is not filled up yet

    int search(int searchItem) const;
    // returns the index of the list element
    // that is equal to the parameter value.

    void insert(int newElement);
    // inserts a new element to the end of the list.

    void remove(int removeElement);
    // removes the element with the index
    // passed as the parameter value.

    void printList() const;
    // prints the elements of the list

    listType(); 
    // constructor.

private:
    int list[1000]; 
    // variable to store the list elements
    int length;  
    // variable to store the size of the list at a given instance.
};

the implementation file saved as listTypeImp.cpp

#include<iostream>
#include "listType.h"
// angular brackets are for system provided header files
// double quotes for user defined header files.

using namespace std;

bool listType::isEmptyList() const
{
    if (length>0)
        return true;
    else return false;
}

bool listType::isFullList() const
{
    if (length==1000)
        return true;
    else return false;

}

void listType::insert(int newElement)
{
    length++;
    list[length-1] = newElement;
}

listType::listType()
{
    length = 0;
}


void listType::printList() const
{
    for(int i=0;i<length;i++)
    {
        cout<<i<<"th element of the list is"<<list[i]<<endl;
    }
}

void listType::remove(int removeElement)
{
    for(int i=removeElement;i<length;i++)
    {
        list[i] = list[i+1];
    }
    length--;
}

int listType::search(int searchItem) const
{
    for(int i=0;i<length;i++)
    {
        if (list[i]==searchItem)
            return i;
    }
    return -1;
}


the executable file (test.cpp)

#include "listType.h"

void main()
{
    listType newlist = listType();
    listType oldlist;

    newlist.insert(6);
    newlist.insert(5);
    newlist.insert(9);
    newlist.printList();
    newlist.remove(0);
    newlist.printList();
    newlist.insert(37);
    newlist.insert(42);
}

ERROR coming is:
Thread stopped
C:\Mansoor\College\CIS 4100\test.exe:
Fault: acess violation at 0xcafedead:
read of address 0xcafedead
Mack1982 is offline   Reply With Quote
Old Apr 26th, 2006, 7:09 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I'm going to take a look at your code, but you tell your professor I said he/she is full of shit. One who is teaching the language should know that 'main' returns an int and write it accordingly. SHEEEEEEEEEEEEEEEEEEEEEEEEEESH, blow my nose in my jockeys and call me a sticky bun!!!!!!!!!!!!!!!!!

EDIT: the program compiles and runs, using VC++ 2005, and produces the following output:
Quote:
0th element of the list is6
1th element of the list is5
2th element of the list is9
0th element of the list is5
1th element of the list is9
I'll try it with Borland 6 and let you know.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 26th, 2006, 7:24 PM   #6
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 242
Rep Power: 3 Seif is on a distinguished road
his is void main so it doesn't return an int DaWei j/k man, my lecturer got most of my class into the same filthy habit
Seif is offline   Reply With Quote
Old Apr 26th, 2006, 7:34 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Shit fire, Seif, I realize that it's declared 'void'. That's what the hell I said. "'main' returns an int" implies more than a return statement, it implies a proper definition. That form shown is incorrect, despite the fact that some compilers tolerate it.

At any rate, this is the output produced when compiled with Borland 6.
Quote:
0th element of the list is6
1th element of the list is5
2th element of the list is9
0th element of the list is5
1th element of the list is9
You need to set up your environment correctly, if anyone in charge there knows what the hell they're doing.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 26th, 2006, 7:35 PM   #8
Mack1982
Programmer
 
Join Date: Dec 2004
Posts: 34
Rep Power: 0 Mack1982 is on a distinguished road
I have visual C++ too ... but i dont' know how to compile in it.
In BORLAND there is only one button,.. just press it and the code compiles.
Mack1982 is offline   Reply With Quote
Old Apr 26th, 2006, 7:38 PM   #9
Mack1982
Programmer
 
Join Date: Dec 2004
Posts: 34
Rep Power: 0 Mack1982 is on a distinguished road
One more question,.
If one has a working program not written in this format i-e all the code is in a single file. One can easily break it into the above kind of files, right?
Mack1982 is offline   Reply With Quote
Old Apr 26th, 2006, 7:44 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
I have visual C++ too ... but i dont' know how to compile in it.
In BORLAND there is only one button,.. just press it and the code compiles.
Time to quit relying on yo' mama and yo' prof and learn a few simple things on your own. In answer to your last question, 'yes'. One doesn't have to break it up, even. It's an organizational thangy that you'll understand the first time you have an application containing multiple thousands of lines of code written by a team of programmer's using a handful of third-party libraries.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC