Product management OOP - Assignment 1 Design a C++ class to hold information of
ID: 3625215 • Letter: P
Question
Product management
OOP - Assignment 1
Design a C++ class to hold information of a product. The information includes Product Code, Product Name and Unit Price. Product Code contains exactly 6 characters, which the first two characters are the upper-case letters (A-Z) and the four next characters are digits (0-9). Product Name contains no more than 30 characters. Unit Price is double type with 2 numbers after decimal point, and the price must be positive and less than $1000000 (<1000000).
Write a C++ program to do the below tasks:
Allow user to input name of file that contains information of all products. This file may contain some products when you load it at the first time.
Allow users to add new information of as many products as they want. After checking validation of all data (including that the code could not be duplicated), save those information into the program, then they are ready to be saved into a file in task 2.6.
Search product by code from all products in file that was inputted in task 2.1 and products which are added in task 2.2. Then display the result.
Display all information of products in file that was inputted in task 2.1 and products which are added in task 2.2.
Sort by product code and display all information of products in file that was inputted in task 2.1 and products which are added in task 2.2.
Save all products loaded from task 2.1 and added from task 2.2 into a file which has a given name.
Submission Requirements
At the beginning of your program, include comments reflecting accurate information for you in the format as below:
You should draw UML model to describe your class and functions in detail on separate paper and submit it with your program.
Explanation / Answer
Check these all codes, hope it will help u much.
#include
#include
#include
#include
class order
{
int order_no;
int product_code;
int quantity;
public:
float totalprice(float x, int y);
void invoice(void);
void getorder(void);
void line(void);
};
class product
{
char product_name[20];
int product_code;
float unit_price;
public:
/*
product(char pn[30], int pc, float up)
{
pn = product_name;
pc = product_code;
up = unit_price;
}
*/
float getprice();
void getproducts();
void displayproducts();
};
#include
#include
#include
#include
#include
#include "product.h"
#include "order.h"
void product::getproducts(void)
{
cout << "Enter Product Name : ";
cin.getline(product_name,20);
cout << "Enter Product Code : ";
cin >> product_code;
cout << "Enter Unit Price : ";
cin >> unit_price;
cin.ignore();
}
float product::getprice(void)
{
return unit_price;
}
void product::displayproducts(void)
{
cout << "Product Name : " << product_name;
cout << " Product Code : " << product_code;
cout << " Unit Price : " << unit_price;
}
void order::getorder(void)
{
cout << "Enter Order No : ";
cin >> order_no;
cout << "Enter Product Code : ";
cin >> product_code;
cout << "Enter Quantity : ";
cin >> quantity;
}
float order::totalprice(float a, int b)
{
return a*b;
}
void order::invoice(product p)
{
char dateStr [9];
cout << " ";
line();
cout << " |" << " ABC Company Invoice Date: " << _strdate(dateStr) << " | ";
line();
cout << " |" << " Order No | " << order_no << " |" ;
cout << " |" << " Product code | " << product_code << " |" ;
cout << " |" << " Quantity " << quantity << " @ Unit Price | *** | ";
line();
cout << " |" << " Total price | *** | ";
line();
}
void order::line(void)
{
for(int x=0;x<44;x++)
cout << "-";
}
main()
{
product P[3]; //object of type product
order O[3]; // object of type order
for(int i=0;i<3;i++)
{
cout << " Enter Product " << (i+1) << " Information";
cout << " -------------------------- ";
P[i].getproducts();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Product P" << (i+1);
cout << " --------- ";
P[i].displayproducts();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Enter Order Information " << (i+1);
cout << " ------------------------ ";
O[i].getorder();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Order No: " << (i+1);
cout << " --------- ";
O[i].invoice();
}
getche();
}
=======================================================================
#include
#include
#include
#include
class product
{
char product_name[20];
int product_code;
public:
float unit_price;
float getunit();
float getprice();
void getproducts();
void displayproducts();
};
class order: public product
{
int order_no;
int product_code;
int quantity;
public:
float totalprice(float x, int y);
void invoice();
void getorder(void);
void line(void);
};
#include
#include
#include
#include
#include
#include "derived.h"
void product::getproducts(void)
{
cout << "Enter Product Name : ";
cin.getline(product_name,20);
cout << "Enter Product Code : ";
cin >> product_code;
cout << "Enter Unit Price : ";
cin >> unit_price;
cin.ignore();
}
float product::getprice(void)
{
return unit_price;
}
void product::displayproducts(void)
{
cout << "Product Name : " << product_name;
cout << " Product Code : " << product_code;
cout << " Unit Price : " << unit_price;
}
void order::getorder(void)
{
cout << "Enter Order No : ";
cin >> order_no;
cout << "Enter Product Code : ";
cin >> product_code;
cout << "Enter Quantity : ";
cin >> quantity;
}
float order::totalprice(float a, int b)
{
return a*b;
}
void order::invoice()
{
char dateStr [9];
cout << " ";
line();
cout << " |" << " ABC Company Invoice Date: " << _strdate(dateStr) << " | ";
line();
cout << " |" << " Order No | " << order_no << " |" ;
cout << " |" << " Product code | " << product_code << " |" ;
cout << " |" << " Quantity " << quantity << " @ Unit Price | *** | " << getprice();
line();
cout << " |" << " Total price | *** | ";
line();
}
void order::line(void)
{
for(int x=0;x<44;x++)
cout << "-";
}
main()
{
product P[3]; //object of type product
order O[3]; // object of type order
for(int i=0;i<3;i++)
{
cout << " Enter Product " << (i+1) << " Information";
cout << " --------------------------- ";
P[i].getproducts();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Product P" << (i+1);
cout << " --------- ";
P[i].displayproducts();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Enter Order Information " << (i+1);
cout << " ------------------------ ";
O[i].getorder();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Order No: " << (i+1);
cout << " --------- ";
O[i].invoice();
}
getche();
}
======================================================================
#include
#include
#include
#include
class product
{
public:
/*
product(char pn[30], int pc, float up)
{
pn = product_name;
pc = product_code;
up = unit_price;
}
*/
char product_name[20];
int product_code;
float unit_price;
float getunit();
float getprice();
void getproducts();
void displayproducts();
};
class order: public product
{
public:
int order_no;
int product_code;
int quantity;
float totalprice(float x, int y);
void invoice();
void getorder(void);
void line(void);
};
=================================================
#include
#include
#include
#include
class product
{
public:
/*
product(char pn[30], int pc, float up)
{
pn = product_name;
pc = product_code;
up = unit_price;
}
*/
char product_name[20];
int product_code;
float unit_price;
void getproducts();
void displayproducts();
};
class order: public product
{
public:
int order_no;
int product_code;
int quantity;
float getUnit(int a);
float totalprice(float x, int y);
void invoice();
void getorder(void);
void line(void);
};
===========================================================
#include
#include
#include
#include
#include
#include "derived.h"
void product::getproducts(void)
{
cout << "Enter Product Name : ";
cin.getline(product_name,20);
cout << "Enter Product Code : ";
cin >> product_code;
cout << "Enter Unit Price : ";
cin >> unit_price;
cin.ignore();
}
void product::displayproducts(void)
{
cout << "Product Name : " << product_name;
cout << " Product Code : " << product_code;
cout << " Unit Price : " << unit_price;
}
void order::getorder(void)
{
cout << "Enter Order No : ";
cin >> order_no;
cout << "Enter Product Code : ";
cin >> product_code;
cout << "Enter Quantity : ";
cin >> quantity;
}
float order::totalprice(float a, int b)
{
return a*b;
}
void order::invoice()
{
char dateStr [9];
cout << " ";
line();
cout << " |" << " ABC Company Invoice Date: " << _strdate(dateStr) << " | ";
line();
cout << " |" << " Order No | " << order_no << " |" ;
cout << " |" << " Product code | " << product_code << " |" ;
cout << " |" << " Quantity " << quantity << " @ Unit Price | *** | " << (float)unit_price;
line();
cout << " |" << " Total price | *** | ";
line();
}
void order::line(void)
{
for(int x=0;x<44;x++)
cout << "-";
}
main()
{
product P[3]; //object of type product
order O[3]; // object of type order
for(int i=0;i<3;i++)
{
cout << " Enter Product " << (i+1) << " Information";
cout << " --------------------------- ";
P[i].getproducts();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Product P" << (i+1);
cout << " --------- ";
P[i].displayproducts();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Enter Order Information " << (i+1);
cout << " ------------------------ ";
O[i].getorder();
}
cout<<" ";
for(int i=0;i<3;i++)
{
cout << " Order No: " << (i+1);
cout << " --------- ";
O[i].invoice();
}
getche();
}
----------------------------------------------------------------------------------------------------------
void order::invoice()
{
char dateStr [9];
cout << " ";
line();
cout << " |" << " ABC Company Invoice Date: " << _strdate(dateStr) << " | ";
line();
cout << " |" << " Order No | " << order_no << " |" ;
cout << " |" << " Product code | " << product_code << " |" ;
cout << " |" << " Quantity " << quantity << " @ Unit Price | *** | " << (float)unit_price;
line();
cout << " |" << " Total price | *** | ";
line();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.