Answer to Question #17217 in C++ for JP

Question #17217
My son has a homework to do and he has no time to do it right.
Is a simple work, consisting in introducing ID of product, Name, Quantity and Price. Then it must sort articles by name, id, qty or price. It must give the total amount in stock...
They must not use tables, only the subjects they have already learned. This HW must be ready until Thrusday.
How much can it cost to verify and complete what is already done, or give some tips ...?
Thanks.
JP
1
Expert's answer
2012-10-26T10:04:12-0400
#include<iostream>

#include <string>

#include<conio.h>

using namespace std;




class Product {

public :

string id,name;

double price;

int quantity;

};




int main()

{

static int sum = 0;

string id, name;

double price;

int quantity;

Product *test;

Product products[3] ;

for (int i = 0; i < 3; i++) {

test = new Product();

cout << i+1 << " Product" << endl;

cout << "Enter id: " ;

cin >> test->id;

cout << "Enter name: ";

cin >> test->name;

cout << "Enter price: ";

cin >> test->price;

cout << "Enter quantity: ";

cin >> test->quantity;

products[i] = *test;

cout << endl;

}




cout << "Enter id to search: " ;

cin >> id;




for (int i = 0; i < 3; i++) {

if (products[i].id == id){

cout << id << " was found" << endl;

}

}




_getch();

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS