![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
Code TAG??
LIKE for start [code] FOR END [\CODE] |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#5 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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:
__________________
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 |
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 244
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#7 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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:
__________________
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 |
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Dec 2004
Posts: 34
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#10 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|