0% found this document useful (0 votes)
7 views2 pages

Invoice Lab Practical

The lab assignment requires creating an Invoice class for a hardware store, including pseudo code, class definition, data members, a constructor, and set/get functions. The class should calculate the invoice amount based on quantity and price per item, with input validation for positive values. Students must demonstrate the class's capabilities through a test program and submit their work in both zipped and PDF formats on Moodle.

Uploaded by

thandorh2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Invoice Lab Practical

The lab assignment requires creating an Invoice class for a hardware store, including pseudo code, class definition, data members, a constructor, and set/get functions. The class should calculate the invoice amount based on quantity and price per item, with input validation for positive values. Students must demonstrate the class's capabilities through a test program and submit their work in both zipped and PDF formats on Moodle.

Uploaded by

thandorh2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Assignment #1: Creating an Invoice Class

Lab Objectives

In this lab, you are required to:

▪ Write the pseudo code.


▪ Create a class definition.
▪ Declare data members.
▪ Define a constructor.
▪ Define set and get functions.
▪ Write an application to demonstrate the capabilities of class Invoice.
▪ Compile and execute the program.
▪ Compare your output with the sample output provided.
▪ Submit your lab assignment for assessment on Moodle.
▪ Submit as: (a) as a zipped folder (use link named lab assignment
1(CODE)) (b) as a PDF(use the link named lab assignment 1 (PDF)).

Description of the Problem

Create a class called Invoice that a hardware store might use to represent an invoice for
an item sold at the store. An Invoice should include four pieces of information as data
members—a part number (type string), a part description (type string), a quantity of
the item being purchased (type int) and a price per item (int). [Note: Use numbers that
contain decimal points (e.g., 2.75)—called floating-point values—to represent rand
amounts.] Your class should have a constructor that initializes the four data members.
Provide a set and a get method for each data member. In addition, provide a member
function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies
the quantity by the price per item), then returns the amount as an int value. If the
quantity is not positive, it should be set to 0. If the price per item is not positive, it
should be set to 0. Write a test program that demonstrates class Invoice’s capabilities.
It is important to validate your input.

Hints:

▪ To solve this exercise, revisit your previous solutions.


▪ The input values for the quantity and the price per item must be validated
before they can be used to set the corresponding data members.
✓ This should be done both in the constructor and in the
appropriate set functions.
▪ The function header for getInvoiceAmount should be int getInvoiceAmount ().
▪ Be sure to follow consistent programming conventions.

Sample Output:

Part number: 12345


Description: Hammer
Quantity: 100
Price per item: R5
Invoice amount: R500

Quantity cannot be negative. Quantity set to 0. Invoice data members modified.

Part number: 123456


Description: Saw
Quantity: 0
Price per item: R10
Invoice amount: R0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy