Posts

Showing posts with the label cpp program

C++ program to perform data transformation Min-max and Z score Normalization

Simple C++ program to perform data transformation using min-max normalization, z-score normalization and decimal scaling operation. Code: #include<iostream> #include<math.h> using namespace std; int main() { int n; double sum=0; cout<<"Enter The Number of values:"; cin>>n; int a[n],r1,r2; for(int i=0;i<n;i++) { cin>>a[i]; } cout<<"Enter starting and ending range for normalization:"; cin>>r1>>r2; double max = a[0]; int min = a[0]; for (int i = 0; i <n; i++) { if (a[i] > max) { max = a[i]; } else if (a[i] < min) { min = a[i]; } } float v[n];double temp; for(int i=0;i<n;i++) { temp=double(double(double(a[i]-min)*(r2-r1))/(max-min))+ r1; v[i]=temp; } cout<<"normalization by Min-max"<<endl; cout<<"Values a...

C++ program to implement correlation analysis on nominal and numeric data type.

Simple C++ program to implement correlation analysis on nominal and numeric data type. Code: #include<iostream> #include<math.h> using namespace std; int main() { int n1, i, sum=0, sum1=0; floatmean_A, mean_B, std_A, std_B, corr; cout<< "Enter the number of data: " <<endl; cin>> n1; int x[n1]; cout<< "Enter the data for A: " <<endl; for(i=0; i<n1; i++) { cin>> x[i]; } int y[n1]; cout<< "Enter the data for B: " <<endl; for(i=0; i<n1; i++) { cin>> y[i]; } for(i=0; i<n1; i++) { sum = sum + x[i]; sum1 = sum1 + y[i]; } mean_A = (float)sum / n1; mean_B = (float)sum1 / n1; sum=0; sum1=0; for(i=0; i<n1; i++) { sum = sum + pow(x[i] - mean_A, 2); sum1 = sum1 + pow(y[i] - mean_B, 2); } std_A = sqrt(sum / n1); std_B = sqrt(sum1 / n1); sum=0; for(i=0; i<n1; i++) { sum = sum + x[i] * y[i]; } corr = ((sum - (n1 * mean_A * mean_B))/(n1 * std_A * std_B...

C++ program to perform Data cleaning operation with Binning Method

Simple C++ program to perform Data cleaning operation on data set which include treatment of missing value, smoothing of noisy data by binning method.   Code: #include<iostream> #include<algorithm> #include<math.h> using namespace std; int main() { int num,i, j, d, e, in, k, sum, b1, b2; int n, r, r1, r2; cout << "Enter the total number of data: " << endl; cin >> num; int a[num]; cout << "Enter the values: " << endl; for(i=0; i<num; i++) { cin >> a[i]; } sort(a, a+num); while(true) { cout << "Enter your choice: " << endl; cout << "1. Equal-Depth Binning" << endl; cout << "2. Equal-Width Binning" << endl; cout << "3. Exit" << endl; cin >> in; if(in==1) { cout << "Enter the depth of bin: " << endl; cin >> d; cout << endl; e = num / d; int b[e][d], avg[e], m...

C++ program to identify heaviest ball from 8-ball problem (3-3-2 method)

Easy C++ code for 8-ball problem with 3-3-2 method Code: #include <iostream> using namespace std; int main() {     int a[8],side1=0,side2=0;     for(int i=0;i<8;i++)     {     cout<<"Enter the weight of ball no "<<i+1<<endl;     cin>>a[i];     }     for(int i=0;i<3;i++)     {         side1=side1+a[i];         side2=side2+a[i+4];     }     cout<<"putting each side 3 balls and remaining two will be out"<<endl;     cout<<endl<<"\t\tside 1\t\t\tside 2"<<endl;     cout<<"\t\t"<<side1<<"\t\t\t"<<side2<<endl;     if(side1>side2)     {         cout<<"side 1 has more weight, so dividing side 1 into group of two and remaining onw ball would be out"<<endl;         side1=si...

C++ program to identify heaviest ball from 8-ball problem (4-4 method)

Simple C++ program to implement 8-ball problem with 4 ball method: Code: #include <iostream> using namespace std; int main() {     int a[8],side1=0,side2=0;     for(int i=0;i<8;i++)     {     cout<<"Enter the weight of ball no "<<i+1<<endl;     cin>>a[i];     }     for(int i=0;i<4;i++)     {         side1=side1+a[i];         side2=side2+a[i+4];     }     cout<<"putting each side 4 balls: "<<endl;     cout<<endl<<"\t\tside 1\t\t\tside 2"<<endl;     cout<<"\t\t"<<side1<<"\t\t\t"<<side2<<endl;     if(side1>side2)     {         cout<<"side 1 has more weight, so dividing side 1 having 4 balls into group of 2 balls:"<<endl;         side1=side2=0;       ...