Challenge

Project 1

Aim:

To find out the best vendor from whom the purchases can be made based on the number of commodities and respective prices to pay a reasonable price.

Program:

#include <iostream>
#include<string.h>
#include<fstream>
using namespace std;

int main()
{
    int n,m;
    string commodities[100];
    int vendors[100][100];
    string name;
    int purchase[100];
    fstream my_file;
    int total[m];
    my_file.open("my file",ios::out);
    cout<<"enter no of commodities"<<endl;
    cin>>n;
    cout<<"enter no of vendors";
    cin>>m;
    cout<<"Enter the commodities";
    for(int i=0;i<n;i++)
    {
        cin>>commodities[i];
    }
    cout<<"enter the details of vendors";
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>vendors[i][j];
        }
    }
  
    cout<<"Enter the Person of Commodities to be brought"<<endl;
    cin>>name;
    for(int i=0;i<n;i++)
    {
        cout<<"Enter no of"<<commodities[i]<<"needed";
        cin>>purchase[i];
    }
  
    my_file<<"commodities\t\t"<<"vendor 1\t"<<"  Vendors 2"<<endl;
    for(int i=0;i<n;i++)
    {
        my_file<<commodities[i]<<"\t\t\t";
        for(int j=0;j<m;j++)
        {
           
            my_file<<vendors[i][j]<<"\t\t\t\t";
        }
           my_file<<endl;
    }
    my_file<<"the Person of Commodities to be brought "<<name<<endl;
    for(int i=0;i<n;i++)
    {
        my_file<<"Enter no of\t"<<commodities[i]<<"needed\t"<<purchase[i]<<"\n";
    }
    for(int j=0;j<m;j++)
    {
        total[j]=0;
    }
    for(int j=0;j<m;j++)
    {
    for(int i=0;i<n;i++)
    {
     total[j]=total[j]+(purchase[i]*vendors[i][j]);   
    }
    cout<<"Total of "<<"Vendor "<<j+1<<"is\t"<<total[j]<<endl;
    my_file<<"Total of "<<"Vendor "<<j+1<<"is\t"<<total[j]<<endl;
    }
    int max=total[0];
    for(int i=1;i<m;i++)
    {
        if(max>total[i])
        {
            max=total[i];
        }
    }
    cout<<"Vendor with total amount"<<max<<"is best for purchase"<<endl;
    my_file<<"Vendor with total amount"<<max<<"is best for purchase"<<endl;
    return 0;
}

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.

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.