Question

Edit this C++ code to show the output as well.

#include<iostream>
#include<cstring>


using namespace std;


class Product {
private:

   // private variables
   int id_number;
   char pDescription[40];
   int mId;
   double productPrice;
   double productMarkUp;
   int qty;

public:

   // constructor
   Product() {
       id_number = 0;
       strcpy_s(pDescription, "");
       mId = 0;
       productPrice = 0.0;
       productMarkUp = 0.0;
       qty = 0;
   }

   // constructor with arguments
   Product(int a, char *b, int c, double d, double e, int f) {
       id_number = a;
       strcpy_s(pDescription, b);
       mId = c;
       productPrice = d;
       productMarkUp = e;
       qty = f;
   }


   // setter functions
   void setID(int a) {
       id_number = a;
   }
   void setDescription(char *a) {
       strcpy_s(pDescription, a);
   }
   void setMId(int a) {
       mId = a;
   }
   void setProductPrice(double a) {
       productPrice = a;
   }
   void setProductMarkUp(double a) {
       productMarkUp = a;
   }
   void setQty(int a) {
       qty = a;
   }


   // getter functions
   int getID() {
       return(id_number);
   }
   char* getDescription() {
       return(pDescription);
   }
   int getMId() {
       return(mId);
   }
   double getProductPrice() {
       return(productPrice);
   }
   double getProductMarkUp() {
       return(productMarkUp);
   }
   int getQty() {
       return(qty);
   }

   // print Product data
   void print() {
       cout << "The Product's Identification Number: " << id_number;
       cout << "\nThe Product's Manufacture's 'Identification Number: " << mId;
       cout << "\nThe Product's Wholesale Price: " << productPrice;
       cout << "\nThe Product's Mark-Up Percentage: " << productMarkUp;
       cout << "\nThe Product's Description: " << pDescription;
       cout << "\nThe Quantity Of The Product In Stock: " << qty;
   }
};


// main
int main() {
   int a;
   char b[40];
   int c;
   double d, e;
   int f;

   // user inputs
   cout << "Enter The Product's Identification Number:\n";
   cin >> a;
   cout << "Enter The Product's Manufacture's 'Identification Number:\n";
   cin >> c;
   cout << "Enter The Product's Wholesale Price:\n";
   cin >> d;
   cout << "Enter The Product's Mark-Up Percentage:\n";
   cin >> e;
   cout << "Enter The Product's Description:\n";

   // ignore
   cin.ignore();
  
  
   // description from user
   cin.getline(b, 40);
   cout << "Enter The Quantity Of The Product In Stock:\n";
   cin >> f;


   // product object
   Product product(a, b, c, d, e, f);

   // display data
   cout << "\n\nDisplay Result : -\n";
   product.print();


   return(0);
}

O C:WINDOWSystem32\cmd.exe ============= =========== ========== ==== Office Supply Product Information = ======== ======== ==

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Your code is pretty good and working fine. The only thing you want to print the output as printed in given image. here the the edited answer for your problem. I you have any doubt please feel free to ask.

Here is the complete code for the following question :

#include<iostream>
#include<cstring>

//function declaration which call thw main, When user input 'Y'
void call_main();
using namespace std;


class Product {
private:

// private variables
int id_number;
char pDescription[40];
int mId;
double productPrice;
double productMarkUp;
double productRetailPrice;
int qty;

public:

// constructor
Product() {
id_number = 0;
strcpy_s(pDescription, "");
mId = 0;
productPrice = 0.0;
productMarkUp = 0.0;
productRetailPrice = 0.0;
qty = 0;
}

// constructor with arguments
Product(int a, char* b, int c, double d, double e, int f, double g) {
id_number = a;
strcpy_s(pDescription, b);
mId = c;
productPrice = d;
productMarkUp = e;
qty = f;
productRetailPrice = g;
}


// setter functions
void setID(int a) {
id_number = a;
}
void setDescription(char* a) {
strcpy_s(pDescription, a);
}
void setMId(int a) {
mId = a;
}
void setProductPrice(double a) {
productPrice = a;
}
void setProductMarkUp(double a) {
productMarkUp = a;
}
void setQty(int a) {
qty = a;
}
void setProductRetailPrice(double a)
{
productRetailPrice = a;
}


// getter functions
int getID() {
return(id_number);
}
char* getDescription() {
return(pDescription);
}
int getMId() {
return(mId);
}
double getProductPrice() {
return(productPrice);
}
double getProductMarkUp() {
return(productMarkUp);
}
double getProductRetailPrice()
{
return(productRetailPrice);
}
int getQty() {
return(qty);
}

// print Product data
void print() {

cout << "|===============================================================================|\n";
cout << "|\t\t\tOffice Supply Product Information\t\t\t|\n";
cout << "|===============================================================================|\n";
cout << "|===============================================================================|\n";
cout << "|\t\tIdentification Number:\t\t" << id_number << "\t\t\t\t|\n";
cout << "|\t\tDescription:\t\t\t" << pDescription << "\t\t\t\t|\n";
cout << "|\t\tManufacturing:\t\t\t" << mId << "\t\t\t\t|\n";
cout << "|\t\tWholesale Price:\t\t" << productPrice << "\t\t\t\t|\n";
cout << "|\t\tMark-Up Percentage:\t\t" << productMarkUp << "\t\t\t\t|\n";
cout << "|\t\tQuantity in Stock:\t\t" << qty << "\t\t\t\t|\n";
cout << "|===============================================================================|\n";
cout << "Office Supply Product Retail Price: $" << productRetailPrice << "\n";

//ask user if he want to continue
cout << "Do you wish to enter any more products?\n";
cout << "Enter 'Y' or 'N' : ";

char ch;
cin >> ch;
//if user pres y, re run the main else exist
if (ch == 'Y')
{
call_main();
}
}
};


// main
int main() {
int a;
char b[40];
int c;
double d, e, g;
int f;

// user inputs
cout << "Enter The Product's Identification Number: ";
cin >> a;
cout << "Enter The Product's Manufacture's 'Identification Number: ";
cin >> c;
cout << "Enter The Product's Wholesale Price: ";
cin >> d;
cout << "Enter The Product's Mark-Up Percentage: ";
cin >> e;
cout << "Enter Reatail Price of Product: ";
cin >> g;
cout << "Enter The Product's Description: ";
// ignore
cin.ignore();
//// description from user
cin.getline(b, 40);
cout << "Enter The Quantity Of The Product In Stock: ";
cin >> f;


//// product object
Product product(a, b, c, d, e, f, g);

// display data
cout << "\n\nDisplay Result : -\n";

product.print();


return(0);
}
//since we can not directly call main from Product class, we use this method to call main to dd a new product
void call_main()
{
main();
}

---------------------------------------------------------------------------------------------------------------------------------------------------

Output :

Enter The Products Identification Number: 10001 Enter The Products Manufactures Identification Number: 5020 Enter The Pro

Add a comment
Know the answer?
Add Answer to:
Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • Use C++ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <cstring> using namespace std; /I Copy n...

    Use C++ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <cstring> using namespace std; /I Copy n characters from the source to the destination. 3 void mystrncpy( ???) 25 26 27 28 29 11- 30 Find the first occurrance of char acter c within a string. 32 ??? mystrchr???) 34 35 36 37 38 39 / Find the last occurrance of character c within a string. 40 II 41 ??? mystrrchr ???) 42 43 45 int main() char userInput[ 81]; char...

  • #include <iostream> #include <string> #include <cstring> using namespace std; class Node{       private:       ...

    #include <iostream> #include <string> #include <cstring> using namespace std; class Node{       private:        int data;        Node* nextNodePtr;           public:        Node(){}               void setData(int d){            data = d;        }               int getData(){            return data;        }               void setNextNodePtr(Node* nodePtr){                nextNodePtr = nodePtr;        }                ...

  • #include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured...

    #include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured in feet and inches. */ class FeetInches { private: int feet; // The number of feet int inches; // The number of inches /** The simplify method adjusts the values in feet and inches to conform to a standard measurement. */ void simplify() { if (inches > 11) { feet = feet + (inches / 12); inches = inches % 12; } } /**...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[...

    The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[SIZE];    int player, choice, win, count;    char mark;    count = 0; // number of boxes marked till now    initBoard(board);       // start the game    player = 1; // default player    mark = 'X'; // default mark    do {        displayBoard(board);        cout << "Player " << player << "(" << mark...

  • #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace...

    #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace std; void DisplayMenu() {    cout << "1. E games\n";    cout << "2. T games\n";    cout << "3. M games\n";    cout << "4. Total Games\n";    cout << "5. Exit\n"; } double total(double egames, double tgames, double mgames) {    int totalgames = egames + tgames + mgames;    cout << "There are " << totalgames << " games\n";    return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT