C/C++ :: How To Access Linked List Functions From Stack Class Without Functions
Mar 20, 2014
I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.
We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.
As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.
NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.
Stack.h
#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;
[Code]...
View 3 Replies
ADVERTISEMENT
Jul 11, 2013
I have a big problem with searching a solution for getting access on getters and setters of the derived classes of an interface.
Interface:
class IfParam
{
public:
IfParam();
};
Now I have a derived class for each needed datatype. E.g.
class Int32Param: public IfParam
{
public:
Int32Param();
Int32Param(IfParam* l_param);
int getValue();
void setValue(int l_value);
private:
[Code]...
My Problem now ist getting access to the getters/setters over the interface. I wish I could initialize the Params like this:
IfParam* param = new Int32Param();
param.setValue(12);
IfParam* param = new StringParam();
param.setValue("String");
But to have access to the getter/setter I have to declaire the functions in the interface as generic functions. But how? I tried to use temlates, but then i have to declaire IfParam as IfParam<int>. Thats a problem because in my original program I do not know which TypeParam the IfParam interface will be initialized with when I create the pointer.
View 7 Replies
View Related
Feb 28, 2014
Suppose I make a class, something like having the constructor being invoked first makes sense, I don't have a problem with that. But, how could I limit access to functions until certain functions are called? Perhaps this isn't built into the language so you can't. And maybe this problem never comes up. For example if you have a set() and get() functions, if they are both public functions, there doesn't seem to be a way for the compiler at least now if set() never gets called you shouldn't call get(). I just see this as error prone if you need to use libraries, you have to know not to do it from documentation instead of something the compiler can check.
View 11 Replies
View Related
Jul 5, 2013
I'm developing a stack using a linked list. I have to develop two friend functions to do something with the list. But I've tried to understand the friendship, without any consistent result.
Extract of code:
Code:
class Element {
public:
int Data;
Element *nextElement;
Element(int Element) {Data = Element; nextElement = NULL;}
~Element() { }
[Code] ....
I have no errors, but I cannot access the private properties of the class.
The thing I would like to do is: sum the elements of the stack with a friend function.
View 7 Replies
View Related
May 3, 2013
At the moment im trying out with pointing to an array of functions. I got this working as following:
typedef void (* functionPtr) ();
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}
void loop(){
A=0;
B=1;
functions[A][b]();
}
But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:
error: argument of type 'void (Basic::)()' does not match 'void (*)()'
View 2 Replies
View Related
Oct 11, 2014
I'm trying to print a single linked list backward with functions/classes. I have created the main file and 3 header files. But I'm getting an error on one of the header files, linkedListIterator after adding #include "linkedListType.h". It says that "linkedLlistType.h" is calling itself. And when I try to run it, I get an error of "too many header files." I have tried changing the headers many times, but nothing seems to work.
.cpp file:
/*(Printing a single linked list backward) Include the functions reversePrint and recursiveReversePrint, as discussed in this chapter, in the class linkedListType. Also, write a program function to print a (single) linked list backward. (Use either the class unorderedLinkedList or the class orderedLinkedList to test your function.)*/
#include "linkedListType.h"
#include "orderedLinkedList.h"
#include "linkedListIterator.h"
#include <iostream>
using namespace std;
struct nodeType
[Code] ....
header files:
[URL] .... (error in this header file)
[URL] ....
View 9 Replies
View Related
Apr 17, 2013
From my book:
"A static function might have this prototype:
static void Afunction(int n);
A static function can be called in relation to a particular object by a statement such as the following:
aBox.Afunction(10);
The function has no access to the non-static members of aBox. The same function could also be called without reference to an object. In this case, the statement would be:
CBox::Afunction(10);
where CBox is the class name. Using the class name and the scope resolution operator tells the compiler to which class Afunction() belongs."
Why exactly cant Afunction access non-static members?
View 7 Replies
View Related
Apr 1, 2013
I am unable to make any logical algorithm to access middle of stack. I am using stack implemented with linkedlists, I have following functions available for stack like push,pop,top.
View 6 Replies
View Related
Sep 16, 2013
Question: How can we write functions to access various fields?
Example: A phone number -- it has an area code, exchange & subscriber -> (123)-456-7890
How can we write a function to access the various fields of a phone number both in a particular class & in the main?
View 5 Replies
View Related
Jan 20, 2013
I have the following code which will find the minimum size queue among a vector of queues and the minimimum size queue will enqueue(push) the int
std::vector<std::queue<int> > q
void enqueue(){
int min_index = 1;
std::size_t size = q.size();
for( i=2; i<size; i++) //accessing loop of queues
if(q[min_index].size() > q[i].size())
min_index = i; // Now q[min_index] is the shortest queue
q[min_index].push(int)
}
Now my another paradigm is to do the dequeue(pop) operation in another function(shown below), bt i need to access all vector of queues declared in enqueue() function. how can i access the loop of queues given in the enqueue() function?
void dequeue(){
//q.pop operation , access all the queues in the loop of queues
}
willq[i].pop(int);
Access all the queues in the enqueue function and does the pop operation?
View 1 Replies
View Related
Oct 23, 2014
I am trying to program a stack based linked list. Something very weird is happening with my program. Whenever i want to print with cout<< in specific places, it actually changes the data of the stack. Also, using endl after the cout also changes the data of the program.
#include <iostream>
using namespace std;
class node {
public:
int number;
node* nextPtr=NULL;
[Code] ....
View 7 Replies
View Related
Jan 19, 2014
I need to access the functions of the derived classes from a vector of objects of base classes (can't believe I wrote it). Here a Diagram for you to understand:
So as you see, I need the function Use() from the Usable class, to be able to be called from the vector like:
inventory.at(x)->Use()
View 14 Replies
View Related
Oct 14, 2014
How can I access a function in a child form from another child form of a same owner?
View 1 Replies
View Related
May 12, 2014
So im trying to write a code that will take data in from a user and when that user enters specific character then i want to pop the top of the stack and place that node on a new stack. Then if the user enters a different specific character then i want to place what was just popped off the stack back on to the original stack. Anyways i'm just testing what i have without all the complicated stuff with the specific characters, but i get an error and i'm not not well versed in exception handling. So this is what i have so far. the push seems to work well but the pop seems to be giving me problems.
Stack::Stack(){
top = NULL;
bottom = NULL;
}
//method to push a line of text onto the stack
void Stack::push(string data)
[Code] .....
View 4 Replies
View Related
Nov 10, 2013
struct Node {
int entry;
Node *next;
Node(); //1
Node(int item, Node *link = NULL); //2
[Code] .....
Implement: 1 2 3 4 5
and overload operator <<, >>, =
View 1 Replies
View Related
Nov 27, 2014
Basically what are the advantages and disadvantages of having an array implementation vs linked list implementation for a stack?
View 1 Replies
View Related
Nov 29, 2014
I had the following question in my exam paper and only got 2.5 out of a possible 7 marks.
Given the Matrix class:
class Matrix {
public:
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix<T>&operator=(const Matrix<T>& rhs);
[code]....
Use the linkedStackType class (Linked list implementation of stack) and write a function reverseRows to reverse the order of rows in the matrix. Note that reverseRows is not a member function of the Matrix class therefore only the public interface of matrix can be used.
template<class Type>
struct nodeType {
Type info;
nodeType<Type> *link;
[code]....
View 2 Replies
View Related
Feb 13, 2013
I'm trying to implement 2d array to simulate linked list for stack and I faced several difficulties doing so.
How do I implement from Top to Bottom ordering? How do I check random index value for validity?
Source-code:
Code:
#include <iostream>
using namespace std;
int myTop, index, nex = -1;
int twoDimentionalArray[25][3], L[25];
[Code].....
And one more thing: how do I get straight 0 from 25 index in the first coulumn?
View 1 Replies
View Related
Mar 30, 2013
Say I have 3 classes:
class Player {
public:
virtual func1();
[code]....
Say in my main class, I have a function fight(Player p1, Player p2) and I would like to do something like this in the fight function, given that p1 is the human and p2 is the computer:
//function fight()
fight(Player p1, Player p2) {
p1.func2();
}
//using function fight()
fight(human, computer);
When I compile the program, I got this: error: ‘class Player’ has no member named 'func2()' What can I do to allow p1 to call func2 inside fight()? I'm not allowed to use pointers as the parameter for fight() and have to use the signature fight(Player p1, Player p2).
View 6 Replies
View Related
Jan 21, 2014
The compiler creates virtual table for the base class and also for the derived class whether we override it or not.
That means each class has separate virtual table. when we get the size of the each class with out any data members... the size of base is -- 4 bytes(64 bit) and the size of derived is -- 1
The size of base class 4 is correct since it creates the virtual pointer internally and its size is member data + virtual pointer, but it in this case I have included any data members so it has given 4 byts.
But why in case of derived is 1 byte, since it the derived class has overridden the virtual function from base, this will also contains the virtual pointer which will be pointing to derived class Vtable, it the size of the class suppose to be 4 instead of 1 byte.
#include<iostream>
class A{
public:
[Code].....
View 1 Replies
View Related
Nov 4, 2014
I'm working on a list of functions that can create a unique ID for a computer. Here's what i have so far:
GetAdapterInfo();
RegOpenKeyEx();
GetVolumeInformation():
CoCreateGUID();
Are there any other functions that do this?
View 1 Replies
View Related
Apr 12, 2014
I am getting an Unhandled exception at 0x00CB569E in AusitnHorton_Chapter17_7.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.
And, It puts a little yellow arrow at this line:
cout << nodepointer->value << " ";//print current node
when I try to run this program.
//Program:Make a ListNode and simple linked list class. Test the linked list class by adding varous numbers to the list and then test for membership. Then include a search function that returns the position of x on the list, if not found return -1.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstring>
#include <fstream>
#include <cctype>
using namespace std;
class LinkedList
[Code] ....
View 3 Replies
View Related
Feb 14, 2015
how use a new class on functions?
class test
{
public:
int a=0;
[Code]....
i did something like these with my image class, but i get wrong results.
View 6 Replies
View Related
Dec 31, 2012
I want to know how to list the all the symbols in the shared library(dll or .so file). I dont want commands like nm or objdump or depends.exe . I want to get the list of functions available in shared library programmatically at runtime (after calling loadlibrary/dlopen and GetProcAddress/dlsym). Is there a way to get the complete signature of functions in a shared library?
View 2 Replies
View Related
Apr 6, 2013
Just a few moments ago i was just doing foolish things in c++ and discovered something new. Though some of you might have known this, for those who dont know, take a look at the follwing 2 small programs,
#include <iostream.h>
#include <conio.h>
void main();
void loop()
[Code]....
so here is my problem. i think u wud have figured out what m trying to do above. am actually calling the main() of the class and from there, i want to call the usual main... the problem is, during A.main()'s run, if i refer to main(); , that call represents itself, that it, it is like it calls itself. How on earth can i call the outside main?
View 7 Replies
View Related
May 19, 2013
I have a class as follows:
class testa {
public:
testa_b();
~testa_b();
testa_c();
}
Then I have defined some variables in testa_b:
testa::testa_b()
{
double aa = 1.0;
}
What is the easiest way to make testa_c() can use the aa defined in testa_b() (without declaring them in the class)?
View 3 Replies
View Related