Question

C++ ONLY This is your first ever program using object oriented methodology. In this assignment you...

C++ ONLY

This is your first ever program using object oriented methodology. In this assignment you will need to instantiate (create) object(s) and invoke their member functions to perform different tasks. The program is to keep track of customer orders and to create reports as needed.

At minimum you will need several objects to be instantiated throughout the program such as:

  • An OrderProcessor object
  • Order objects (stored in an array)

Let’s get to class design now.

Class Design

class Order: represents customer order information

  • Private member data:
    • customer name
    • product name
    • unit price
    • quantity
    • order date (03/xx/2018)    xx is 2-digit date
  • Public constructors: (must use member initializer syntax as shown on etudes modules)
    • Default constructor: set price to 0.0, quantity to 0, date to 03/01/2018
    • Non-default constructor taking customer name, product name, price, quantity, and date as parameters
  • Public destructor: output “Order <customer> <product> dtor called …”
  • Public member functions: (must declare const function if they do not modify member data)
    • Accessor/mutator for all member data

class OrderProcessor: maintain a list of Order objects (array of Order objects)

  • Private member data:
    • Company name
    • Company web site (www.xyz.com (Links to an external site.)Links to an external site. for example)
    • An array of 32 Order objects (namely order_list)
    • Order count (the actual number of Orders in the system)
  • Public constructors: (must use member initializer syntax as shown on etudes modules)
    • Default constructor: set order count to 0
    • Non-default constructor: take a string for company name and a string for company web site (must set order count to 0 similar to default constructor)
  • Public destructor: output “OrderProcessor dtor called …\n”
  • Public member functions: (must declare const function if they do not modify member data)
    • Accessor/mutator for company name, company web site, and order count
    • Init: Use a for loop similar to the LoadVehicle function in assignment 3 to randomly generate 16 Orders (array half full) as follows:
      • Randomly generate a number 1-5: for each number you can assign a Product name (such as iPhone 7, Samsung 52-inch SmartTV, Dell Inspiron 15-inch Laptop, …) and its associated price per unit (you can make up the unit price value however appropriate)
      • Randomly generate a Product quantity for the order (1-10)
      • Randomly generate an order day (1-30 for the month of November)
      • Now call the mutators in Order object to properly initialize the current Order element in the Order array: customer name (declaring a string array of 16 names inside the Init function), Product name, unit price, quantity, order date (of November, 2016). An example of this setting is: order_list[i].set_product (“iPhone 7”);
      • NOTE: don’t forget to update the order count member to 16
    • AddOrder: ask user input for a new Order with all needed Order info and add it to the end of the array
    • ReportOrderDetails: list all orders with a nice format as follows

Company:                                                            Web-site:

                Customer      Product    Quantity       Unit Price      Total cost       Order date               

Implementation/Coding Requirements

  • Must follow Google style for naming convention in class declarations and definitions (member data variables, member function names etc …)
  • Must define constructors/destructor/member functions separately from class declarations
  • Must follow our lecture on the program structure for classes in single file compilation

Main Program

  • Instantiate a non-default OrderProcessor object
  • Invoke Init member function for the object
  • Invoke ReportOrderDetails
  • Use a loop to add three more Orders to the OrderProcessor
  • Invoke ReportOrderDetails
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your C++ Code :D

================================================================================

#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;

class Order
{
string customer;
string product;
float price;
int quantity;
int date;
public:
Order()
{
price = 0.0;
quantity = 0;
date = 1;
}
Order(string name, string prod, float p, int q, int d)
{
customer = name;
product = prod;
price = p;
quantity = q;
date = d;
}
  
string get_customer()
{
return customer;
}
  
void set_customer(string name)
{
customer = name;
}
  
string get_product()
{
return product;
}
  
void set_product(string name)
{
product = name;
}
  
float get_price()
{
return price;
}
  
void set_price(float p)
{
price = p;
}
  
int get_quantity()
{
return quantity;
}
  
void set_quantity(int q)
{
quantity = q;
}
  
int get_date()
{
return date;
}
  
void set_date(int d)
{
date = d;
}
friend class OrderProcessor;
};

class OrderProcessor
{
string company;
string website;
Order obj[32];
int count;
public:
OrderProcessor()
{
count = 0;
}
  
OrderProcessor(string comp, string web)
{
company = comp;
website = web;
count = 0;
}
  
string get_company()
{
return company;
}
  
void set_company(string comp)
{
company = comp;
}
  
string get_website()
{
return website;
}
  
void set_website(string web)
{
website = web;
}
  
void AddOrder()
{
string temp;
cout<<"\nEnter Name of Customer:";
cin>>temp;
obj[count].set_customer(temp);
cout<<"\nEnter Name of Product:";
cin>>temp;
obj[count].set_product(temp);
float cost;
cout<<"\nEnter Cost:";
cin>>cost;
obj[count].set_price(cost);
int t;
cout<<"\nEnter Quantity:";
cin>>t;
obj[count].set_quantity(t);
cout<<"\nEnter Date:";
cin>>t;
obj[count].set_date(t);
count++;
cout<<"\n\nDetails Successfully Added!";
}
  
void init()
{
string products[6] = {"\0", "Samsung TV", "Apple iPhone 7", "Redmi Note 6", "Playstation 4", "HP Laptop"};
string names[6] = {"\0", "Tom", "Susan", "Tony", "Sheldon", "Joey"};
float prices[6] = {0, 40000, 70000, 14000, 40000, 25000};
count = 16;
for(int i = 0; i < 16; i++)
{
int num = rand() % 5 + 1;
obj[i].set_customer(names[num]);
num = rand() % 5 + 1;
obj[i].set_product(products[num]);
obj[i].set_price(prices[num]);
num = rand() % 10 + 1;
obj[i].set_quantity(num);
num = rand() % 30 + 1;
obj[i].set_date(num);
}
}
  
void ReportOrderDetails()
{
cout<<"\n\nCompany: "<<company<<"\t\t\tWebsite: "<<website;
cout<<"\n\n\tCustomer\tProduct\t\t\tQuantity\tUnit Price\tTotalCost\tOrder Date";
for(int i = 0; i < count; i++)
{
cout<<"\n\t"<<obj[i].get_customer()<<"\t\t"<<obj[i].get_product()<<"\t\t"<<obj[i].get_quantity()<<"\t\t"<<obj[i].get_price()<<"\t\t"<<(obj[i].get_quantity() * obj[i].get_price())<<"\t\t03/"<<obj[i].get_date()<<"/2018";
}
}
};


int main()
{
OrderProcessor object("Fortune", "www.fortune.com");
object.init();
object.ReportOrderDetails();
for(int i = 0; i < 3; i++)
{
cout<<"\n\nADDING "<<(i+1)<<" / 3";
object.AddOrder();
}
object.ReportOrderDetails();
return 0;
}

=====================================================================================

If you have any queries, do drop a comment. Thank You :D

Add a comment
Know the answer?
Add Answer to:
C++ ONLY This is your first ever program using object oriented methodology. In this assignment you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • In object-oriented programming, the object encapsulates both the data and the functions that operate on the...

    In object-oriented programming, the object encapsulates both the data and the functions that operate on the data. True False Flag this Question Question 101 pts You must declare all data members of a class before you declare member functions. True False Flag this Question Question 111 pts You must use the private access specification for all data members of a class. True False Flag this Question Question 121 pts A private member function is useful for tasks that are internal...

  • Antique Class Each Antique object being sold by a Merchant and will have the following attributes:...

    Antique Class Each Antique object being sold by a Merchant and will have the following attributes: name (string) price (float) And will have the following member functions: mutators (setName, setPrice) accessors (getName, getPrice) default constructor that sets name to "" (blank string) and price to 0 when a new Antique object is created a function toString that returns a string with the antique information in the following format <Antique.name>: $<price.2digits> Merchant Class A Merchant class will be able to hold...

  • C++ edit: You start with the code given and then modify it so that it does...

    C++ edit: You start with the code given and then modify it so that it does what the following asks for. Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Modify the Employee class so that it has two more fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that...

  • Java Object Array With 2 Elements In 1 Object

    1. Create a UML diagram to help design the class described in Q2 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Person class object; should they be private or public? Determine what class methods are required; should they be private or public?2. Write Java code for a Person class. A Person has a name of type String and an age of type integer.Supply two constructors: one will be...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • This small project is geared to get you started on writing Object Oriented program using either...

    This small project is geared to get you started on writing Object Oriented program using either Java or C++. Create a class called Person that will hold information about a single individual. This class should have a data section that consists of the following: Variable Name Data Type firstName string lastName string address string The Person class should have the following mutators: setFirstName(string first); setLastName(string last); setAddress(string address); The Person class should have the following accessors: string getFirstName(); string getLastName();...

  • IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5...

    IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5 OVERVIEW This homework builds on Hw4(given in bottom) We will modify the classes to do a few new things We will add copy constructors to the Antique and Merchant classes. We will overload the == operator for Antique and Merchant classes. We will overload the + operator for the antique class. We will add a new class the "MerchantGuild." Please use the provided templates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT