Skip to content

Instantly share code, notes, and snippets.

@iamOgunyinka
Last active April 3, 2019 03:10
Show Gist options
  • Save iamOgunyinka/8990210da77ce3683065fa23f8789c6b to your computer and use it in GitHub Desktop.
Save iamOgunyinka/8990210da77ce3683065fa23f8789c6b to your computer and use it in GitHub Desktop.
//customer.cpp
#include "customer.h"
//Constructor
customerType::customerType( std::string firstName, std::string lastName, int an)
{
setCustomerInfo(firstName, lastName, an);
}
//Define method to set customer information
void customerType::setCustomerInfo( std::string firstName, std::string lastName, int an)
{
this->firstName = firstName;
this->lastName = lastName;
accountNumber = an;
}
//Define method to set account number
void customerType::setAccountNumber(int an)
{
accountNumber = an;
}
void customerType::setFirstName( std::string firstname)
{
this->firstName = firstname;
}
void customerType::setLastName( std::string lastname)
{
this->lastName = lastname;
}
void customerType::addVideo(videoType v)
{
rentedVideos.push_back(v);
}
bool customerType::returnVideo( std::string title)
{
bool fg = false;
for (int kk = 0; kk < rentedVideos.size(); kk++)
{
if (rentedVideos[kk].getTitle() == title)
{
rentedVideos.erase(rentedVideos.begin() + (kk + 1));
fg = true;
break;
}
}
return fg;
}
void customerType::printAccountNumber()
{
cout << "Account Number:" << accountNumber << endl;
}
int customerType::getAccountNumber() const
{
return accountNumber;
}
int customerType::getNoOfRentedVideos() const
{
return rentedVideos.size();
}
//define method to display customer
void customerType::display()
{
std::cout << "First Name: " << firstName << std::endl;
std::cout << "Last Name: " << lastName << std::endl;
std::cout << "Account Number: " << accountNumber << std::endl;
std::cout << "Rented Videos: " << std::endl;
for (int kk = 0; kk < rentedVideos.size(); kk++)
{
//videoType v =rentedVideos[kk]
cout << rentedVideos[kk] << endl;
}
}
//define method
bool customerType::operator==(const customerType & c)
{
return((firstName == c.firstName) && (lastName == c.lastName));
}
bool customerType::operator!=(const customerType & c)
{
return((firstName != c.firstName) && (lastName != c.lastName));
}
std::ostream& operator<<( std::ostream& out, const customerType& c)
{
out << "First Name: " << c.firstName << std::endl;
out << "Last Name: " << c.lastName << std::endl;
out << "Account Number: " << c.accountNumber << std::endl;
out << "Rented Videos: " << endl;
for (int kk = 0; kk < c.rentedVideos.size(); kk++)
{
//videoType v =rentedVideos[kk]
out << c.rentedVideos[kk] << std::endl;
}
return out;
}
//customerListType.cpp
#include "customerListType.h"
#include <iostream>
#include <string>
using namespace std;
//Implementatioon of customerSearch method to search for a customer
bool customerListType::customerSearch(int accountNumber) const
{
for ( auto cp_iter = GetRootNode(); cp_iter != nullptr; cp_iter = cp_iter->next ) {
if ( cp_iter->data.getAccountNumber() == accountNumber ) return true;
}
return false;
}
//Implementation of addCustomer method to add customer
bool customerListType::addCustomer(customerType c)
{
bool fg = false;
if (!customerSearch(c.getAccountNumber()))
{
insertLast(c);
fg = true;
}
return fg;
}
//Implementation of printCustomerList method to print the customers
void customerListType::printCustomerList() const
{
for ( auto cp_iter = GetRootNode(); cp_iter != nullptr; cp_iter = cp_iter->next ) {
cp_iter->data.display();
}
}
//customerListType.h
#pragma once
#ifndef _CUSTOMERLIST_TYPE_H
#define _CUSTOMERLIST_TYPE_H
#include <string>
#include "customer.h"
#include "unorderedLinkedList.h"
#include "videoType.h"
using namespace std;
//customerListType class declaration
class customerListType :public unorderedLinkedList<customerType>
{
public:
//Declaration of customerSearch method
bool customerSearch(int accountNUmber) const;
//Declaration of addCustomer method
bool addCustomer(customerType c);
//Declaration of printCustomerList method
void printCustomerList() const;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment