Answer to Question #9194 in C++ for adam

Question #9194
Write a function readSaleRecord prototyped by

int readSaleRecord(unsigned & itemId, double & itemPrice,
char & discountType, unsigned & quantity);

so that the execution of this function will retrieve 4 fields, i.e. the item ID itemId, the original item price itemPrice, the discount type discountType and the quantity quantity, from the stdin device. The returned value will be 0 if the reading has been successful, and will be non-zero if otherwise. In fact, when the record is not successfully read, the returned value will be 1 if it's due to receiving 0 for the item ID or hitting the EOF, and will be -1 if otherwise.

Explain (i) what do the ampersands "&" do in the prototyping; (ii) is this function still syntactically correct if some of these 4 ampersands are removed from the function header; and (iii) will your program still work if one of these 4 ampersands is removed and why. Please also use the following interface for the input.

-> item ID: 101024
-> full item price: 199.95
Expert's answer
int readSaleRecord(unsigned & itemId, double & itemPrice,char & discountType, unsigned & quantity);{
readSaleRecord( itemId, itemPrice, discountType, quantity);
cout << " item ID :" << itemId;
cout << " full item price : " << itemPrice;
cout << " discount Type : " << discountType;
cout << " quantity : " << quantity;
if (cin==good) = return true
else return 1;
cout << "n\n\n"
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be the first!

Leave a comment

New on Blog