Project 1
Live Batch Esakki Vigneswaran
project code :-
#include <iostream>// my input and output header file
#include <fstream>// my file handling header file
#include <cstring>//my string header file
using namespace std;
class IT_Department// my class and class name is IT_Department
{
public:// public access specifier
IT_Department()// my constructor
{
int n_commodities , n_vendors;//the is are user input variables
cout<<"enter the number of commodities :- ";
cin>>n_commodities;//giving the user data
cout<<"enter the number of vendors :- ";
cin>>n_vendors;//giving the user data
int** commodities = new int*[n_commodities];//double pinter variable giving the DMA
for(int i=0;i < n_commodities; i++)//for loop for array
{
commodities[i]=new int[5];//DMA to the commodities
}
cout<<"enter the commodities :- "<<endl;
for(int i=0;i<n_commodities;i++)//for loop entering the data
{
cout<<""<<endl;
cout<<"commodities "<<i+1<<" :- "<<endl;
cout<<"enter the number of laptops :- ";
cin>>commodities[i][0];//giving the user data to array index
cout<<"enter the number of mouse's :- ";
cin>>commodities[i][1];//giving the user data to array index
cout<<"enter the number of headset's :- ";
cin>>commodities[i][2];//giving the user data to array index
cout<<"enter the number of laptop bags :- ";
cin>>commodities[i][3];//giving the user data to array index
cout<<"enter the number of adapters :- ";
cin>>commodities[i][4];//giving the user data to array index
}
int** vendors = new int*[n_vendors];//double pinter variable giving the DMA
for(int i=0; i<n_vendors; i++)//for loop for array
{
vendors[i]=new int[5];//DMA to the commodities
}
cout<<"enter the vendors :- "<<endl;
for (int i=0; i<n_vendors; i++)//for loop entering the data
{
cout<<""<<endl;
cout<<"vendors "<<i+1<<" :- "<<endl;
cout<<"enter the laptop price :- ";
cin>>vendors[i][0];//giving the price of laptop stores in array index
cout<<"enter the mouse price :- ";
cin>>vendors[i][1];//giving the price of mouse stores in array index
cout<<"enter the headset price :- ";
cin>>vendors[i][2];//giving the price of headset stores in array index
cout<<"enter the laptop bag price :- ";
cin>>vendors[i][3];//giving the price of laptop bag stores in array index
cout<<"enter the adapter price :- ";
cin>>vendors[i][4];//giving the price of adapter stores in array index
}
fstream data;// creating the .txt file using fstream
data.open("data",ios::out);//opening the file
if(!data){//if condition is not true if body works
cout<<" file not created "<<endl;
}
else{//if condition is not true else body works
cout<<""<<endl;
cout<<"file is created successfully"<<endl;
for(int i=0;i<n_commodities;i++){//for loop for stores the data to the file
data<<"commodities "<<i+1<<" :- "<<endl;
data<<"the number of laptops :- ";
data<<commodities[i][0]<<endl;//saving the commodities array data into the file
data<<"the number of mouse's :- ";
data<<commodities[i][1]<<endl;//saving the commodities array data into the file
data<<"the number of headset's :- ";
data<<commodities[i][2]<<endl;//saving the commodities array data into the file
data<<"the number of laptop bags :- ";
data<<commodities[i][3]<<endl;//saving the commodities array data into the file
data<<"the number of adapters :- ";
data<<commodities[i][4]<<endl;//saving the commodities array data into the file
}
for(int j=0;j<n_vendors;j++){
data<<"vendors "<<j+1<<" :- "<<endl;
data<<"the price laptops :- ";
data<<vendors[j][0]<<endl;//saving the vendors array data into the file
data<<"the price mouse's :- ";
data<<vendors[j][1]<<endl;//saving the vendors array data into the file
data<<"the price headset's :- ";
data<<vendors[j][2]<<endl;//saving the vendors array data into the file
data<<"the price laptop bags :- ";
data<<vendors[j][3]<<endl;//saving the vendors array data into the file
data<<"the price adapters :- ";
data<<vendors[j][4]<<endl;//saving the vendors array data into the file
}
int** best_vendor=new int*[5];//double pinter variable giving the DMA
int64_t** total_vendor=new int64_t*[3];//double pinter variable giving the DMA
for(int i=0; i<n_commodities;i++)//for loop for array
{
best_vendor[i]=new int[5];
total_vendor[i]=new int64_t[3];
}
for(int i=0; i<1; i++)// this for loop for calculating the difference in two vendors
{
best_vendor[i][0]=vendors[0][0]-vendors[1][0];//calculating the laptop difference price
best_vendor[i][1]=vendors[0][1]-vendors[1][1];//calculating the mouse price difference
best_vendor[i][2]=vendors[0][2]-vendors[1][2];//calculating the headset price difference
best_vendor[i][3]=vendors[0][3]-vendors[1][3];//calculating the laptop price difference
best_vendor[i][4]=vendors[0][4]-vendors[1][4];//calculating the adapter price difference
cout<<""<<endl;
//displaying the differences' in prices
cout<<"difference between vendors laptop :- "<< best_vendor[i][0]<<endl;
cout<<"difference between vendors mouse :- "<< best_vendor[i][1]<<endl;
cout<<"difference between vendors headset :- "<< best_vendor[i][2]<<endl;
cout<<"difference between vendors laptop bag :- "<< best_vendor[i][3]<<endl;
cout<<"difference between vendors adapter :- "<< best_vendor[i][4]<<endl;
cout<<""<<endl;
cout<<" -->best purchaser is vendor 2 <-- ";
}
}
}
};
int main()//main function
{
IT_Department obj;//constructor object
return 0;//return 0
}
OUTPUT'S :-


--------------------------------------------------------------------------------------------------------------------------------------------------------------
file(.dat or .txt) OUTPUT :-

---------------------------------------------------------------------------------------------------------------------------------------------------
ONLINE_GDB code screenshot :-




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