• Four fields: id with type int, name of type string, nbStocks of type int and price of type double. •A static variable NbArticle that computes the number of Stock objects. •A constructor that creates a Stock with the specified id, name, nbStocks and price. •The getter and setter methods. Object Oriented Design & Programming •Two methods named DecrementStock() and IncrementStock() that decrement and increment respectively by one the number of a Stock. •A method named changePrice(int percent) that change the price of a Stock according to the corresponding percent given by its argument and returns the new price. •A method named ToString() that displays the information of a Stock. •Draw the UML diagram for the class. •Write a test program that creates a Stock with arguments given by the user. •Display the number of created Stocks. •Decrement by 2 the number of Stock and then display the number of Stocks. •Increment by 1 the number Stock and then display the number of Stocks. •Add the price of Stock by 20% and then display the new price. •Display the final information of the Stock.
class Stock { int id; string name; int nbStocks; double price; static NbArticle = 0; // increment this in the constructor to count the objects. public Stock(int id, string name, int nbStocks, double price) { // use the setters to initialise the object } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)