Challenge

Project 1

PROJECT1

Solution:

Code:

#include //Header file
using namespace std; //declaration of the namespace

class Commodity
{
//declare variable
int vendor1;
int vendor2;
char name[50];
public:

// Declaration of function
void getdata();

// Declaration of function
void putdata();
};

// Defining the function outside the class
void Commodity::getdata()
{
cout << "Enter vendor1 quotation : ";
cin >> vendor1;
cout << "Enter vendor2 quotation : ";
cin >> vendor2;
cout << "Enter commodity to be purchase : ";
cin >> name;
}

// Defining the function outside the class
void Commodity::putdata()
{
cout << vendor1 << " ";
cout << vendor2 << " ";
cout << name << " ";
cout << endl;
}

// Driver code
int main()
{
// This is an array of objects having maximum limit of 50 commodity
Commodity com[50];
int n, i;
cout << "Enter Commodity to be purchase - ";
cin >> n;

// Accessing the function
for(i = 0; i < n; i++)
{
com[i].getdata();
}
cout << "Commodity Data - " << endl;
cout << "Vendor1 Vendor2 Commodity " << endl;

// Accessing the function
for(i = 0; i < n; i++)
{
com[i].putdata();
}
}

Output:

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.