//include the three classes we created and
//vector for storing the new data
#include
#include
#include "Division.h"
#include "Artifact.h"
#include "Service.h"
#include "Item.h"
using namespace std;
int main()
{//use new operator to dynamically create objects of
primitive
//create three new Devisions
Division* d1 = new Division();
Division* d2 = new Division();
Division* d3 = new Division();
//create three new Artifact
Artifact* a1 = new Artifact();
Artifact* a2 = new Artifact();
Artifact* a3 = new Artifact();
//create three new Sevice
Service* s1 = new Service();
Service* s2 = new Service();
Service* s3 = new Service();
vector Divisions;
vector Artifacts;
vector Services;
//use push_back fnction to push elemetns into the
vector from the back
Divisions.push_back(d1);
Divisions.push_back(d2);
Divisions.push_back(d3);
Artifacts.push_back(a1);
Artifacts.push_back(a2);
Artifacts.push_back(a3);
Services.push_back(s1);
Services.push_back(s2);
Services.push_back(s3);
//artifact and service in the store
Artifacts.clear();
Services.clear();
//vectors become empty
vectorItems;
Items.push_back(a1);
Items.push_back(a2);
Items.push_back(a3);
Items.push_back(s1);
Items.push_back(s2);
Items.push_back(s3);
//a for loop to show total price
for (int i = 0; i < 6; i++)
{
cout <<
Items[i]->GetTotalPrice() << endl;
}
//two for- loops to show the Name and Total Price
of each
for (int i = 0; i < 3; i++)
{//we need to access a member by using ->
operator
cout << "Artifact Number: "
<< i + 1 << " )" << " Name: " <<
Artifacts[i]->GetName() << ". Total Price: " <<
Artifacts[i]->GetTotalPrice() << endl;
}
for (int i = 0; i < 3; i++)
{
cout << "Service Number: "
<< i + 1 << " )" << " Name: " <<
Services[i]->GetName() << ". Total Price: " <<
Services[i]->GetTotalPrice() << endl;
}
system("Pause");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
#include
using namespace std;
//create a class called Division
//declaration section
class Division
{
public:
//member functions
Division();
Division(string inGUID, string inName, string inPhone,
string inDescription);
Division(string inGUID, string inName, string
inPhone
, string inDescription, Division*
inParent);
//record private members under the keyword
private
//hidden attributes
private:
string GUID;
string Name;
string PhoneNumber;
string Description;
Division* Parent;
};//variables stays protected
#include "Division.h"
//Implementation section
Division::Division()
{
}//end of default constructor
Division::Division(string inGUID, string inName, string inPhone,
string inDescription)
{
//initialize private variables
GUID = inGUID;
Name = inName;
PhoneNumber = inPhone;
Description = inDescription;
}
//initialize Parent
Division::Division(string inGUID, string inName, string inPhone,
string inDescription
, Division* inParent)
{
GUID = inGUID;
Name = inName;
PhoneNumber = inPhone;
Description = inDescription;
Parent = inParent;
}
-----------------------------------------------------------
#pragma once
#include
#include "Item.h"
#include "Division.h"//include Division because we need to call the
class
using namespace std;
//create a new class named Artifact
//declaration section
class Artifact : public Item //artifact inherit item
{
public:
//method prototypes
Artifact();
Artifact(string inGUID, string inName, string
inDescription, string inCategory
, Division* inDivisionA, double
inPrice, double inDiscount, string inDiscountType
, double inQuantity);
//member functions
double GetEffectivePrice();
double GetTotalPrice();
string GetName();//add GetName to call the function at
the end
//variable declaration
private:
string GUID;
string Name;
string Description;
string Category;
Division* DivisionA;// can not have the class name so
we call it DivisionA
double Price;
double Discount;
enum DiscountType { amount, percentage };//the
DiscountType can be either amount or percentage
DiscountType dt; //we name DiscountType- dt
double Quantity;
};
#include "Artifact.h"
//impementation section
Artifact::Artifact()
{
}//end of default constructor
Artifact::Artifact(string inGUID, string inName, string
inDescription
, string inCategory, Division * inDivisionA, double
inPrice, double inDiscount
, string inDiscountType, double inQuantity)
{
//initialize private variables
GUID = inGUID;
Name = inName;
Description = inDescription;
Category = inCategory;
DivisionA = inDivisionA;
Price = inPrice;
Discount = inDiscount;
if (inDiscountType == "amount")//setting the right
enum type
dt = amount;
else
dt = percentage;
Quantity = inQuantity;
}
double Artifact::GetEffectivePrice()
{//use an if else statement to specify the discount either an
amount or percentage
if (dt == amount)
return Price - Discount;
else
return Price - Price * Discount /
100;
}
//end of GetEffectivePrice method
double Artifact::GetTotalPrice()
{
return Quantity * GetEffectivePrice();
}
//end of GetTotalPrice
string Artifact::GetName()
{
return Name;
}//end of GetName method
----------------------------------------------------------
#pragma once
class Item
{
public:
//method prototipes
Item();
virtual double GetTotalPrice();
};
#include "Item.h"
Item::Item()
{
}
//end of default constructor
double Item::GetTotalPrice()
{
return 0.0;
}
//end of GetTotalPrice function
------------------------------------------------------
#pragma once
#include "Artifact.h"
//create a class called Service which inherit Artifact
//declaration section
class Service : public Artifact
{
//method prototypes
public:
Service();
Service(string inGUID, string inName, string
inDescription, string inCategory
, Division* inDivisionA, double
inPrice, double inDiscount, string inDiscountType
, double inQuantity, double
inDuration, double inRate, double inRateDiscount
, string inRateDiscountType);
//member functions
double GetEffectiveRate();
double GetTotalPrice();
//own varaible declaration
private:
double Duration;
double Rate;
double RateDiscount;
enum RateDiscountType { amount, percantage
};//RateDiscountType can be
//an amount or percentage
RateDiscountType rt; //we name the class rt
};
#include "Service.h"
//implementation section
Service::Service()
{
}//end of default constructor
Service::Service(string inGUID, string inName, string
inDescription, string inCategory
, Division * inDivisionA, double inPrice, double
inDiscount, string inDiscountType
, double inQuantity, double inDuration, double inRate,
double inRateDiscount
, string inRateDiscountType) : Artifact(inGUID,
inName, inDescription, inCategory
, inDivisionA, inPrice, inDiscount,
inDiscountType, inQuantity)
{
//initialize private variables
Duration = inDuration;
Rate = inRate;
RateDiscount = inRateDiscount;
if (inRateDiscountType == "ammount")
rt = amount;
else
rt = percantage;
}
double Service::GetEffectiveRate()
{
if (rt == amount)
return Rate - RateDiscount;
else
return Rate - Rate * RateDiscount /
100;
}//end of GetEffectiveRate method
double Service::GetTotalPrice()
{
return Artifact::GetTotalPrice() + GetEffectivePrice()
* Duration;
}//end of GetTotalPrice method
-------------------
Use the code developed above.
Implement the KMP or BM string pattern matching algorithm. If your ID number is odd – implement KMP, otherwise (if even) – implement BM.
Driver Program:
Modify the classes’ code (if needed) and write a program to show the items that contain a certain search string (entered by the user) in their name. Your code should traverse only the Items collection that contains pointers to objects of both Artifact and Service classes.
After using the above algorithm to find which items contain the string, display their names and GUID, ordered by the number of occurrences of the string, from high to low.
#include "Division.h"
#include "Artifact.h"
#include "Service.h"
#include "Item.h"
using namespace std;
int main()
{
Division* d1 = new Division();
Division* d2 = new Division();
Division* d3 = new Division();
Artifact* a1 = new Artifact();
Artifact* a2 = new Artifact();
Artifact* a3 = new Artifact();
Service* s1 = new Service();
Service* s2 = new Service();
Service* s3 = new Service();
vector Divisions;
vector Artifacts;
vector Services;
Divisions.push_back(d1);
Divisions.push_back(d2);
Divisions.push_back(d3);
Artifacts.push_back(a1);
Artifacts.push_back(a2);
Artifacts.push_back(a3);
Services.push_back(s1);
Services.push_back(s2);
Services.push_back(s3);
Artifacts.clear();
Services.clear();
vectorItems;
Items.push_back(a1);
Items.push_back(a2);
Items.push_back(a3);
Items.push_back(s1);
Items.push_back(s2);
Items.push_back(s3);
for (int i = 0; i < 6; i++)
{
cout <<
Items[i]->GetTotalPrice() << endl;
}
for (int i = 0; i < 3; i++)
{
cout << "Artifact Number: "
<< i + 1 << " )" << " Name: " <<
Artifacts[i]->GetName() << ". Total Price: " <<
Artifacts[i]->GetTotalPrice() << endl;
}
for (int i = 0; i < 3; i++)
{
cout << "Service Number: "
<< i + 1 << " )" << " Name: " <<
Services[i]->GetName() << ". Total Price: " <<
Services[i]->GetTotalPrice() << endl;
}
system("Pause");
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using namespace std;
class Division
{
public:
Division();
Division(string inGUID, string inName, string inPhone,
string inDescription);
Division(string inGUID, string inName, string
inPhone
, string inDescription, Division*
inParent);
private:
string GUID;
string Name;
string PhoneNumber;
string Description;
Division* Parent;
}
#include "Division.h"
Division::Division()
{
}
Division::Division(string inGUID, string inName, string inPhone,
string inDescription)
{
GUID = inGUID;
Name = inName;
PhoneNumber = inPhone;
Description = inDescription;
}
Division::Division(string inGUID, string inName, string inPhone,
string inDescription
, Division* inParent)
{
GUID = inGUID;
Name = inName;
PhoneNumber = inPhone;
Description = inDescription;
Parent = inParent;
}
-----------------------------------------------------------
#pragma once
#include
#include "Item.h"
#include "Division.h"//include Division because we need to call the
class
using namespace std;
class Artifact : public Item
{
public:
Artifact();
Artifact(string inGUID, string inName, string
inDescription, string inCategory
, Division* inDivisionA, double
inPrice, double inDiscount, string inDiscountType
, double inQuantity);
double GetEffectivePrice();
double GetTotalPrice();
string GetName();//add GetName to call the function at
the end
private:
string GUID;
string Name;
string Description;
string Category;
Division* DivisionA;
double Price;
double Discount;
enum DiscountType { amount, percentage };//the
DiscountType can be either amount or percentage
DiscountType dt; //we name DiscountType- dt
double Quantity;
};
#include "Artifact.h"
Artifact::Artifact()
{
}
Artifact::Artifact(string inGUID, string inName, string
inDescription
, string inCategory, Division * inDivisionA, double
inPrice, double inDiscount
, string inDiscountType, double inQuantity)
{
GUID = inGUID;
Name = inName;
Description = inDescription;
Category = inCategory;
DivisionA = inDivisionA;
Price = inPrice;
Discount = inDiscount;
if (inDiscountType == "amount")//setting the right
enum type
dt = amount;
else
dt = percentage;
Quantity = inQuantity;
}
double Artifact::GetEffectivePrice()
{
if (dt == amount)
return Price - Discount;
else
return Price - Price * Discount /
100;
}
double Artifact::GetTotalPrice()
{
return Quantity * GetEffectivePrice();
}
string Artifact::GetName()
{
return Name;
}
----------------------------------------------------------
#pragma once
class Item
{
public:
//method prototipes
Item();
virtual double GetTotalPrice();
};
#include "Item.h"
Item::Item()
{
}
double Item::GetTotalPrice()
{
return 0.0;
}
------------------------------------------------------
#pragma once
#include "Artifact.h"
class Service : public Artifact
{
public:
Service();
Service(string inGUID, string inName, string
inDescription, string inCategory
, Division* inDivisionA, double
inPrice, double inDiscount, string inDiscountType
, double inQuantity, double
inDuration, double inRate, double inRateDiscount
, string inRateDiscountType);
double GetEffectiveRate();
double GetTotalPrice();
private:
double Duration;
double Rate;
double RateDiscount;
enum RateDiscountType { amount, percantage
};//RateDiscountType can be
RateDiscountType rt; //we name the class rt
};
#include "Service.h"
Service::Service()
{
}
Service::Service(string inGUID, string inName, string
inDescription, string inCategory
, Division * inDivisionA, double inPrice, double
inDiscount, string inDiscountType
, double inQuantity, double inDuration, double inRate,
double inRateDiscount
, string inRateDiscountType) : Artifact(inGUID,
inName, inDescription, inCategory
, inDivisionA, inPrice, inDiscount,
inDiscountType, inQuantity)
{
Duration = inDuration;
Rate = inRate;
RateDiscount = inRateDiscount;
if (inRateDiscountType == "ammount")
rt = amount;
else
rt = percantage;
}
double Service::GetEffectiveRate()
{
if (rt == amount)
return Rate - RateDiscount;
else
return Rate - Rate * RateDiscount /
100;
}
double Service::GetTotalPrice()
{
return Artifact::GetTotalPrice() + GetEffectivePrice()
* Duration;
}//end of GetTotalPrice method
//include the three classes we created and //vector for storing the new data #include #include #include...
using the string.getname function in Player.h // And in Player.cpp; i need to create a function called "get name" and then call it in main.cpp. ConsoleApplication2- Player.h* main.cpp Player.cpp* Player.h* x ConsoleApplication2 (Global Scope) pragma once #include <string> using std: :stri F#ifndef PLAYER #define PLAYER class Player private: string Name; double average public: void setPlayer(double avg, string Name); double ouble getAverage); string getName) #endif
C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...
How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...
Money Lab using arraylists in Java Using the Coin class below create a program with the following requirements Create an arraylist that holds the money you have in your wallet. You will add a variety of coins(coin class) and bills (ones, fives, tens *also using the coin class) to your wallet arraylist. Program must include a loop that asks you to purchase items using the coins in your wallet. When purchasing items, the program will remove coins from the arraylist...
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...
Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...
I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList { private ShoppingItem [] list; private int amtItems = 0; public ShoppingList() { list=new ShoppingItem[8]; } public void add(ShoppingItem item) { if(amtItems<8) { list[amtItems] = ShoppingItem(item);...
By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...
C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...
Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...