Write a function named “createPurchaseOrder” that accepts the quantity (integer), the cost per item (double), and the description (string). It will return a newly created PurchaseOrder object holding that information if they are valid: quantity and cost per item cannot be negative and the description cannot be empty or blank(s). When it is invalid, it will return NULL to indicate that it cannot create such PurchaseOrder object. PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description) {     if(quantity < 0 || costPerItem < 0.0 || description == "")         return NULL;     else     {         PurchaseOrder p = new PurchaseOrder(quantity,costPerItem,description);         return p;     } } what's the issue with this function and how to rewrite it

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++

Write a function named “createPurchaseOrder” that accepts the quantity
(integer), the cost per item (double), and the description (string). It will return a
newly created PurchaseOrder object holding that information if they are valid:
quantity and cost per item cannot be negative and the description cannot be empty or blank(s). When it is invalid, it will return NULL to indicate that it cannot create such PurchaseOrder object.

PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description)
{
    if(quantity < 0 || costPerItem < 0.0 || description == "")
        return NULL;
    else
    {
        PurchaseOrder p = new PurchaseOrder(quantity,costPerItem,description);
        return p;
    }
}
what's the issue with this function
and how to rewrite it
 
File
Edit
Selection
View
Go
Run Terminal Help
.cpp - Visual Studio Code
EXPLORER
C+ user.cpp
C+
.cpp
G degree.cpp
G midtermpractice4.cpp
G• midtempractice3.cpp
G showHelp (1).cpp •
...
6
V OPEN EDITORS 6 UNSAVED
D: > G .cpp > O createPurchaseOrder(int, double, string)
PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description)
{
if(quantity < e || costPerItem < 0.0 || description == "")
1
C+ user.cpp D:\
X & .cpp D:\
2
3
G+ degree.cpp D:\
return NULL;
G+ midtermpractice4.cpp D:\
else
T
G+ midtempractice3.cpp D:\
G• showHelp (1).cpp D:\
PurchaseOrder p = new PurchaseOrder(quantity,costPerItem, description);
7
G+ getnumlist (1).cpp D:\
E #include Untitled-3
return p;
E #include<iostream.h> Untitled-1
10
}
11
v NO FOLDER OPENED
You have not yet opened a folder.
Open Folder
E Code +v M
O ^ x
PROBLEMS
OUTPUT
DEBUG CONSOLE
TERMINAL
You can clone a repository locally.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Clone Repository
Try the new cross-platform PowerShell https://aka.ms/pscore6
To learn more about how to use git
PS C:\Users\Dana Lam> cd "d:\" ; if ($?) { g++ .cpp -o }; if ($?) { .\ }
g++.exe: error: missing filename after '-o'
PS D:\> ]
and source control in VS Code read
our docs.
> OUTLINE
O 0 A 0
E Live Share
Ln 9, Col 6
Spaces: 4
UTF-8
CRLF
C++
Win32 F
Transcribed Image Text:File Edit Selection View Go Run Terminal Help .cpp - Visual Studio Code EXPLORER C+ user.cpp C+ .cpp G degree.cpp G midtermpractice4.cpp G• midtempractice3.cpp G showHelp (1).cpp • ... 6 V OPEN EDITORS 6 UNSAVED D: > G .cpp > O createPurchaseOrder(int, double, string) PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description) { if(quantity < e || costPerItem < 0.0 || description == "") 1 C+ user.cpp D:\ X & .cpp D:\ 2 3 G+ degree.cpp D:\ return NULL; G+ midtermpractice4.cpp D:\ else T G+ midtempractice3.cpp D:\ G• showHelp (1).cpp D:\ PurchaseOrder p = new PurchaseOrder(quantity,costPerItem, description); 7 G+ getnumlist (1).cpp D:\ E #include Untitled-3 return p; E #include<iostream.h> Untitled-1 10 } 11 v NO FOLDER OPENED You have not yet opened a folder. Open Folder E Code +v M O ^ x PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL You can clone a repository locally. Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Clone Repository Try the new cross-platform PowerShell https://aka.ms/pscore6 To learn more about how to use git PS C:\Users\Dana Lam> cd "d:\" ; if ($?) { g++ .cpp -o }; if ($?) { .\ } g++.exe: error: missing filename after '-o' PS D:\> ] and source control in VS Code read our docs. > OUTLINE O 0 A 0 E Live Share Ln 9, Col 6 Spaces: 4 UTF-8 CRLF C++ Win32 F
G softwa
L How to
How to
da How to
O Naviga
E Messa
ь How T
A Globa
A Week
O gener
4 GD X
b Answe
G return
2 In C+
G google
G Compi
e missin
+
A onlinegdb.com
Paused
E Apps
СА
O Instagram
I PM
Teton
f (1) Facebook
W Competitors
My Folder
H Project List + Login
e Sigma
(8) Car Dealership |...
Other bookmarks
E Reading list
SPONSOR DigitalOcean – A quick, easy, and intuitive way to build, deploy, manage, and scale your apps.
OnlineGDB beta
online compiler and debugger for c/c++
Run
O Debug
I Stop
E Share
A Save
{ } Beautify
Language C++ 14
main.cpp
code. compile. run. debug. share.
/******************************************* :
*****************************
IDE
3
Welcome to GDB Online.
My Projects
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
6 Code, Compile, Run and Debug online from anywhere in world.
Classroom new
Learn Programming
7
****************
******:
***********
******************************** /
Programming Questions
9
PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description)
11 - {
10
Sign Up
Login
12
if(quantity < ® || costPerItem < 0.0 || description
"")
13
f
return NULL;
else
115K
14
{
PurchaseOrder p
return p;
}
}
15
16
new PurchaseOrder(quantity, costPerItem,description);
17
18
19
input
stderr
Compilation failed due to following error(s).
10 | PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description)
| Au
About • FAQ • Blog • Terms of Use • Contact Us • GDB
Tutorial • Credits • Privacy
© 2016 - 2021 GDB Online
..
Transcribed Image Text:G softwa L How to How to da How to O Naviga E Messa ь How T A Globa A Week O gener 4 GD X b Answe G return 2 In C+ G google G Compi e missin + A onlinegdb.com Paused E Apps СА O Instagram I PM Teton f (1) Facebook W Competitors My Folder H Project List + Login e Sigma (8) Car Dealership |... Other bookmarks E Reading list SPONSOR DigitalOcean – A quick, easy, and intuitive way to build, deploy, manage, and scale your apps. OnlineGDB beta online compiler and debugger for c/c++ Run O Debug I Stop E Share A Save { } Beautify Language C++ 14 main.cpp code. compile. run. debug. share. /******************************************* : ***************************** IDE 3 Welcome to GDB Online. My Projects GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS 6 Code, Compile, Run and Debug online from anywhere in world. Classroom new Learn Programming 7 **************** ******: *********** ******************************** / Programming Questions 9 PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description) 11 - { 10 Sign Up Login 12 if(quantity < ® || costPerItem < 0.0 || description "") 13 f return NULL; else 115K 14 { PurchaseOrder p return p; } } 15 16 new PurchaseOrder(quantity, costPerItem,description); 17 18 19 input stderr Compilation failed due to following error(s). 10 | PurchaseOrder createPurchaseOrder(int quantity, double costPerItem, string description) | Au About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy © 2016 - 2021 GDB Online ..
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education