Question: C++ Problem Code Isnt working, I assume its a problem with the template set up. Can you please show the code working when you answer,
C++ Problem
Code Isnt working, I assume its a problem with the template set up. Can you please show the code working when you answer, THANK YOU!
//Interface For ADT List
//File ListInterface.h
#ifndef LIST_INTERFACE_H
#define LIST_INTERFACE_H
template
class ListInterface
{
public:
virtual bool isEmpty() const = 0;
virtual int getLength() const = 0;
virtual bool insert(int newPosition, const T& newEntry) = 0;
virtual T getEntry(int position) const = 0;
virtual T replace(int position, const T& newEntry) = 0;
virtual ~ListInterface() {}
};
#endif
//Check.h
#ifndef CHECK_H
#define CHECK_H
#include
#include"ListInterface.h"
#include
#include
using namespace std;
//Use a Linked List to impliment the ADT checkbook
template
class Check
{
//Check should have at least a checknumber, amount and payTo field
int checknumber;
T currentBalance;
string payTo;
Check
public:
//constructor
Check();
//get/set methods.
void setNext(Check* newNext);
Check* getNext() {
return next;
}
double getCurrentBalance();
void setCurrentBalance(T bal);
double deposit(double amt);
double withdraw(double amt);
double getCheckNumber();
double setCheckNumber(int num);
string getPayTo();
void setPayTo(string payto);
};
#include"Check.cpp"
#endif
//Checkbook.h
#ifndef CHECKBOOK_H
#define CHECKBOOK_H
#include
#include"ListInterface.h"
#include"Check.h"
#include
using namespace std;
template
class CheckBook : public ListInterface
{
public:
Check
bool isEmpty() const;
int getLength() const;
//Inserting a new check at new position
bool insert(int newPosition, const T& newEntry);
T getEntry(int position) const;
T replace(int position, const T& newEntry);
};
#include"Checkbook.h"
#endif
//Check.cpp
#include "Check.h"
#include
template
Check
{
checknumber = 0;
currentBalance = 0;
payTo = "";
next = NULL;
}
//get/set methods.
template
void Check
{
next = newNext;
}
template
double Check
{
return currentBalance;
}
template
void Check
{
currentBalance = bal;
}
template
double Check
{
currentBalance += amt;
cout << endl << "Check deposit successful";
}
template
double Check
{
//The balance should not be allowed to go under 0.
if (currentBalance >= amt)
{
currentBalance -= amt;
cout << endl << "Your Check is passed successfully";
}
else
{
cout << endl << "Cannot pass this check. Your balance is too low";
}
}
template
double Check
{
return checknumber;
}
template
double Check
{
checknumber = num;
}
template
string Check
{
return payTo;
}
template
void Check
{
payTo = payto;
}
//Checkbook.cpp
#include "Checkbook.h"
#include
#include"ListInterface.h"
#include"Check.h"
#include
using namespace std;
template
bool Checkbook
{
return (start == NULL);
}
template
int Checkbook
{
Check
int count = 0;
while (temp != NULL)
{
count++;
temp = temp->getNext();
}
return count;
}
//Inserting a new check at new position
template
bool Checkbook
{
Check
int p = 0;
while (temp != NULL)
{
if (p == newPosition) break;
p++;
prev = temp;
temp = temp->getNext();
}
prev->next = newEntry;
newEntry.setNext(temp);
return true;
}
template
T Checkbook
{
Check
int p = 0;
while (temp != NULL)
{
if (p == position) break;
p++;
temp = temp->getNext();
}
return temp->getCurrentBalance();
}
template
T Checkbook
{
Check
int p = 0;
while (temp != NULL)
{
if (p == position) break;
p++;
temp = temp->getNext();
}
temp->setCurrentBalance(newEntry);
return temp->getCurrentBalance();
}
//Main.cpp
#include
#include"Checkbook.h"
#include"Check.h"
#include
using namespace std;
int main()
{
CheckBook
if (CT.isEmpty())
{
cout << endl << "Empty list created";
}
Check
one->setCheckNumber(90);
one->deposit(5000);
one->setPayTo("self");
CT.start = one;
Check
two->setCheckNumber(91);
two->deposit(3000);
two->setPayTo("self");
CT.start->setNext(two);
Check
three->setCheckNumber(92);
three->deposit(1000);
three->setPayTo("self");
two->setNext(three);
Check
four->setCheckNumber(94);
four->withdraw(2000);
four->setPayTo("Jhon");
three->setNext(four);
Check
five->setCheckNumber(95);
five->withdraw(10000);
five->setPayTo("Mary");
four->setNext(five);
five->setNext(NULL);
cout << endl << "Length of the list: " << CT.getLength();
cout << endl << " Balance at position 3: " << CT.getEntry(3);
//cout< cout << endl << "After replacing 5th entry with new amount "; cout << endl << "Balance at position 5: " << CT.replace(5, 2000); //cout< return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
