Project 1
Offline Batch - Kirubhakaran.
#include <iostream> //std cpp library
#include<string.h> //library for string
#include<fstream> //std library for file handling
using namespace std;
string name[3] = {" Ramu ", " Raju ", " Shyam "}; //declare IT staffs name
int n = 5, m=2; //declare commodities and vendor numbers
string commodities[]={" Laptop "," Mouse "," Headset "," LapBag "," Adapter "}; //list of commodities
int *vendors = new int(n*m); //dynamic memory allocate for vendors list
int *purchase = new int(n*3); //dynamic memory allocate for commodities list
fstream data_file;
void ITsupport()
{
cout<< endl<<"Commodities to be purchased for "<< name[0] << endl;
data_file<< endl<<"Commodities to be purchased for "<< name[0] << endl;
for(int i=0;i<n;i++)
{int j=0;
cout<< "Enter no of " << commodities[i] << "needed : ";
cin>>purchase[j*n+i];
data_file<<commodities[i]<<"needed : "<<purchase[j*n+i]<<"\n";
}//to get input from user for ramu
cout<< endl<<"Commodities to be purchased for "<< name[1] <<endl;
data_file<< endl<<"Commodities to be purchased for "<< name[1] << endl;
for(int i=0;i<n;i++)
{int j=1;
cout<<"Enter no of "<<commodities[i]<<"needed : ";
cin>>purchase[j*n+i];
data_file<<commodities[i]<<"needed : "<<purchase[j*n+i]<<"\n";
}//to get input from user for raju
cout<< endl<<"Commodities to be purchased for "<< name[2] <<endl;
data_file<< endl<<"Commodities to be purchased for "<< name[2] << endl;
for(int i=0;i<n;i++)
{int j=2;
cout<<"Enter no of "<<commodities[i]<<"needed : ";
cin>>purchase[j*n+i];
data_file<<commodities[i]<<"needed : "<<purchase[j*n+i]<<"\n";
}//to get input from user for shyam
}
void vendordetails()
{
cout << endl <<"enter the price of vendor 1 :" <<endl;
for(int i=0;i<n;i++)
{ int j=0;
cout<<"Enter price of"<<commodities[i];
cin>>vendors[i*n+j];
}
cout << endl <<"enter the price of vendor 2 :" <<endl;
for(int i=0;i<n;i++)
{ int j=1;
cout<<"Enter price of"<<commodities[i];
cin>>vendors[i*n+j];
} //get vendor price list from user
data_file<<endl<<"commodities\t\t"<<"vendor 1\t"<<" Vendors 2"<<endl<<endl;
for(int i=0;i<n;i++)
{
data_file<<commodities[i]<<"\t\t";
for(int j=0;j<m;j++)
{
data_file<<vendors[i*n+j]<<"\t\t\t";
}
data_file<<endl<<endl;
}//write the vendor details in the file
}
void totalvalue1()
{
int total[m];
cout << endl;
data_file<< endl;
for(int j=0;j<m;j++)
{
total[j]=0;
for(int i=0;i<n;i++)
total[j]=total[j]+(*(purchase+i)* *(vendors+j));
cout<<"Total of "<<"Vendor-"<<j+1<<" is\t"<<total[j]<<endl;
data_file<<"Total of "<<"Vendor-"<<j+1<<" is\t"<<total[j]<<endl;
} //calculate the total value according to the vendors price list
int max=total[0];
for(int i=1;i<m;i++)
{
if(max>total[i])
{
max=total[i];
}
} //to find the best value for purchase
cout<<"Vendor with total amount "<<max<<" is best purchase for "<<name[0] <<endl;
data_file<<"Vendor with total amount "<<max<<" is best purchase for "<<name[0] <<endl;
}
void totalvalue2()
{
int total[m];
cout << endl;
data_file<< endl;
for(int j=0;j<m;j++)
{
total[j]=0;
for(int i=0;i<n;i++)
total[j]=total[j]+(*(purchase+i+5)* *(vendors+j));
cout<<"Total of "<<"Vendor-"<<j+1<<" is\t"<<total[j]<<endl;
data_file<<"Total of "<<"Vendor-"<<j+1<<" is\t"<<total[j]<<endl;
} //calculate the total value according to the vendors price list
int max=total[0];
for(int i=1;i<m;i++)
{
if(max>total[i])
{
max=total[i];
}
} //to find the best value for purchase
cout<<"Vendor with total amount "<<max<<" is best purchase for "<<name[1] <<endl;
data_file<<"Vendor with total amount "<<max<<" is best purchase for "<<name[1] <<endl;
}
void totalvalue3()
{
int total[m];
cout << endl;
data_file<< endl;
for(int j=0;j<m;j++)
{
total[j]=0;
for(int i=0;i<n;i++)
total[j]=total[j]+(*(purchase+i+10)* *(vendors+j));
cout<<"Total of "<<"Vendor-"<<j+1<<" is\t"<<total[j]<<endl;
data_file<<"Total of "<<"Vendor-"<<j+1<<" is\t"<<total[j]<<endl;
}//calculate the total value according to the vendors price list
int max=total[0];
for(int i=1;i<m;i++)
{
if(max>total[i])
{
max=total[i];
}
}//to find the best value for purchase
cout<<"Vendor with total amount "<<max<<" is best purchase for "<<name[2] <<endl;
data_file<<"Vendor with total amount "<<max<<" is best purchase for "<<name[2] <<endl;
}
int main()
{
data_file.open("C:\\Users\\hp\\Desktop\\my file.txt",ios::out); //to create a file in write mode
ITsupport(); // to give the commodities details form user
vendordetails(); // to give the vendor details form user
totalvalue1(); //to calculate the value for IT support 1
totalvalue2(); //to calculate the value for IT support 2
totalvalue3(); //to calculate the value for IT support 3
return 0;
}
