Using OOP concepts write a C++ class to implement a transaction log that records all customer transactions in a store. Each transaction contains the following items:
Customer ID.
Transaction ID.
Cost.
Date.
Time.
Use a dynamic array to record all transactions. The transaction log should offer the following member functions:
Suitable constructors to allocate the dynamic array of transactions.
generateRandomData(): uses the rand() functions to generate random values for all transaction items.
displayData(): print out all the transactions to the screen.
writeDataTofile(): accept a file name as a parameter and write all transaction to the file.
insertTransaction(): takes a transaction as a parameter and insert it at the end of the transaction array.
searchTransaction(): takes a transaction as a parameter and look or it in the transaction array. If the transaction is available then it is printed to the screen if it is not then the function should display a not found message.
deleteTransaction: takes a transaction as a parameter and delete it. If the transaction doesn't exist an error message should be displayed.
Implement a main() function to test all methods mentioned above.
#include <iostream>
#include <cstring>
using namespace std;
// creating classtemplate with name transaction log T//
template <class T>
class transaction{
protected:
char transactionID[50];
int cost;
int date;
int time;
};
//creating template class with name items T
template <class T>
class items: public transaction <double>
{
private:
int customerId;
public:
void read();
void show();
};
//redefinition of virtual function read() in class items
template <class T>
void transaction <T>::read()
{
cout << "Enter tansaction id";
cin.ignore();
cin.getline(transactionID, 50);
cout<<"enter cost of item in dollar";
cin >>cost;
cout<<"enter customerid";
cin >> cost;
cout<< "enter date";
cin>> date;
cout<<"enter time in 12hrs format";
cin>> time;
}
// funtion show() in the class time
template< class T>
class time: public transaction <double>
{
void time <T>:: show()
private:
T time;
public:
void read();
void show();
It helps if you tell us what the actual errors are.
One thing I see that's wrong is this:
1 2 3 4
template< class T>
class time: public transaction <double>
{
void time <T>:: show() // <- this is nonsense
For a prototype of a member function inside a class, you don't need to specify the class scope (because you're already in the class). IE: you don't need the scope operator ::
So you could do this instead:
1 2 3 4
template< class T>
class time: public transaction <double>
{
void show(); // <- fixed
Though you don't seem to be using the :: operator anywhere else so I'm not sure why you thought you needed it there.
how about this i re write the first step no error syntax so far please am i in line
#include <iostream>
#include <cstring>
#include <new>
using namespace std;
// creating classtemplate with name transaction log T//
class transaction{
protected:
int transactionid;
int customerid;
int cost;
int date;
int time;
public:
transaction(int a, int b, int c, int d , int e);
void read(int a, int b, int c, int d, int e);
void show(int a, int b, int c, int d);
};
transaction::transaction (int a, int b, int c, int d , int e)
}
void transaction ::read(int a, int b, int c, int d , int e)
{
transactionid =a;
customerid =b;
cost =c;
date= d;
time= e;
}
int main()
{
cout << "Enter tansaction id\n";
cout<<"enter cost of item in dollar\n";
cout<<"enter customerid\n";
cout<< "enter date\n";
cout<<"enter time in 12hrs format";
}