Posts

Showing posts with the label C Programs

Object of Chair Containing Attributes and Behaviors

Image
Object of Chair Containing Attributes and Behaviors: A simple object in C++ Programming using classes containing attributes and behaviors. Attributes are declared in private variables and behaviors are declared in user defined functions in public inside the class of chair Code of the object of Chair: #include<iostream> #include<string> using namespace std; class chair{ //attributes string c_name; string colour; //behaviour public: void inputdetail(){ cin>>c_name; cin>>colour; } void displaydetail(){ cout<<c_name<<" "<<colour<<" "<<endl; } }; .................................................To get the full code see at the end of the article. Download: To download this code click on the given link below: Download

Programming Fundamentals using C++

Image
Programming Fundamentals: Programming Fundamentals of C++ Programming Language are being shared here for those who started learning C++ Programming Language. In this article shared programs are also available individually on the website with Download Link.On this website you can also found a lot of Presentations and Tips & Tricks and many more. Don't forget to Bookmark this website for more updates and Programming Languages. Today in this post I will share all of my C++ Programming codes here with download links that I recently published on my web. So please read the article till the last. 1- Next Character printing using Static_cast and goto statement: This programming code is used to print a next character by entering any character by using static cast and goto statement in C++ Programming language.You can also get the code by clicking on this Get the Code . You will find the download link at the end of the next page when you will open the link. 2- Find...

Car Pooling Calculator

Image
Car driving cost per day Calculator: #include<iostream> using namespace std; void main() { float milesPD,costPG,avgMPG,pfeesPD,tollsPD; float total_cost; cout<<"enter total miles driven per day:\n"; cin>>milesPD; cout<<"enter cost per gallon of gasoline:\n"; cin>>costPG; cout<<"enter average mile per gallon:\n"; cin>>avgMPG; cout<<"enter parking fees per day:\n"; cin>>pfeesPD; cout<<"enter tolls per day:\n"; cin>>tollsPD; total_cost=(milesPD/avgMPG)*costPG+pfeesPD+tollsPD; cout<<"your cost per day driving to work  "<<total_cost<<"Rupees"<<endl; } Download: To download this code click on the given link below; Download

Hypotenuse Calculator

Image
Hypotenuse Calculator: #include<iostream> #include<cmath> using namespace std; void hypotenuse(int x,int y); void main() { int x,y; hypotenusecalc(x,y); } void hypotenusefcalc(int x,int y) { float hyp; cout<<"Enter perpendicular side"<<endl; cin>>x; cout<<"Enter base side"<<endl; cin>>y; hyp=sqrt(pow(x,2)+pow(y,2)); cout<<hyp<<endl; } Download: To download this code click on the given link below: Download

Calculate Student Grade in Programming Language

Image
Calculate Student Grade in Programming Language: #include<iostream> using namespace std; void gradingsystem(int a); void main() { int a; gradingsystem(a); } void gradingsystem(int a) { cout<<"Enter Average of Numbers\n"; cin>>a; if(a>=90 & a<=100) cout<<"Your Grade is A\n"; else if(a>=80 & a<=89) cout<<"Your Grade is B\n"; else if(a>=70 & a<=79) cout<<"Your Grade is C\n"; else if(a>=60 & a<=69) cout<<"Your Grade is D\n"; else if(a<60) cout<<"Your Grade is F\n"; } Download: To download this code click on the given link below: Download

Minutes Calculator

Image
Calculate total number of minutes from a age: #include<iostream> using namespace std; void minutes(int d,int h,int m); void main() { int d,h,m; minutes(d,h,m); } void minutes(int d,int h,int m) { int min; int d1,h1,m1; d1=0; h1=0;m1=0; cout<<"Enter Month"<<endl; cin>>m; cout<<"Enter Days"<<endl; cin>>d; cout<<"Enter Hours"<<endl; cin>>h; d=d*24; min=(d+h)*60; cout<<"Number of Minutes from "<<"  Day  "<<d1<<"  Month  "<<m1<<"  Hours  "<<h1<<"  To Current Calender Month "<<m<<"  are  "<<min<<endl; } Download: To download this code click on the given link below: Download

Calculate Maximum Number

Image
Calculate Maximum Number: #include<iostream> using namespace std; void maximum(float x,float y,float z); void main() { float x,y,z; maximum(x,y,z); } void maximum(float x,float y,float z) { cout<<"Enter 1st Number"<<endl; cin>>x; cout<<"Enter 2nd Number"<< endl; cin>>y; cout<<"Enter 3rd Number"<<endl; cin>>z; if(x>y & x>z) cout<<"Maximum Number Is     "<<x<<endl; else if(y>x & y>z) cout<<"Maximum Number Is     "<<y<<endl; else if(z>x & z>y) cout<<"Maximum Number Is     "<<z<<endl; } Download: To download this code click on the given link below: Download

XOR Gate for multiple Inputs

Image
XOR Gate for multiple Inputs: //XOR gate for multiple inputs #include<iostream> using namespace std; int xor(int a[5]); void main() { int a[5]; cout<<"Enter 5 inputs (0,1)"<<endl; for(int i=0;i<5;i++) { cin>>a[i]; } cout<<"output : "<<xor(a)<<endl; } int xor(int a[5]) { int count=0; for(int i=0;i<5;i++) { if(a[i]==1) count++; } if(count%2==1) return 1; else  return 0; } Download: To download this code click on the given link below: Download

Logical Gates (AND, OR and NOT)

Image
Logical Gates (AND, OR and NOT): //Logical Gates (AND, OR, NOT) #include<iostream> using namespace std; int and(int x,int y); int or(int x,int y); int not(int x); void main() { int a,b,operation; cout<<"enter 1st input (0,1)"<<endl; cin>>a; cout<<"enter 2nd input (0,1)"<<endl; cin>>b; cout<<"Press 1 for AND operation"<<endl; cout<<"Press 2 for OR operation"<<endl; cout<<"Press 3 for NOT operation"<<endl; cin>>operation; if(operation==1) cout<<and(a,b)<<endl; else if(operation==2) cout<<or(a,b)<<endl; else if(operation==3) cout<<not(a)<<endl; else cout<<"INVALID INPUT"<<endl; } int and(int x,int y) { if(x==1 && y==1) return 1; else return 0; } int or(int x,int y) { if(x==1 || y==1...

Dynamic allocation of memory by using pointers

Image
Dynamic allocation of memory by using pointers: //Dynamic array initialization by using pointers #include<iostream> using namespace std; void main() { int a; cout<<"Enter size of array"<<endl; cin>>a; int *b; b=new int[a];       //this line will allocate the dynamic memory according to the user input //data input in array cout<<"enter "<<a<<" element for array"<<endl; for(int i=0;i<a;i++) { cin>>*(b+i); } //data output for(int j=0;j<a;j++) { cout<<b[j]<<" "; } cout<<endl; } Download: To download this code click on the given link below: Download

Sort the table by checking duplicate values

Image
Sort the table by checking duplicate values: //Solution of Assignment#3 /* Q#1: Write a C++ program which fills the data in a table of 4x4 by taking input from user. Program should prompt an error in case of duplicate entry. After putting the data sort the numbers in the table as given below.*/ #include<iostream> #include<conio.h> using namespace std; void display(int a[16],int i,int j); int duplicate(int a[16],int i,int temp); void sorting(int a[16]); void main() { int a[16]; int temp; int counter; for(int i=0;i<16;i++) { value: cout<<"Enter the values for Table"<<endl; cin>>a[i]; temp=a[i]; counter=duplicate(a,i,temp); if(counter>0) { cout<<"ERROR!!! Value already exists"<<endl; goto value; } } cout<<"Sorted Table is "<<endl; sorting(a); cout<<endl; } void display(...

Dealing With Insurance Companies After A Car Accident

Dealing With Insurance Companies After A Car Accident In an accident, your adversary is not the other driver. It’s actually the insurance companies -- potentially yours and the other driver’s -- who can cause you the most trouble, delays, hassle and money. As personal injury lawyers for personal injury and car accident victims, we make it our goal to ensure that each insurance company knows it is dealing with zealous advocates who fight hard for their clients. When an insurance company sees The Law Offices of Larry B. Litt, involved in a claim for a personal injury victim, it knows that it is in for a fight if it chooses not to compensate our client properly. At the Law Offices of Larry B. Litt, we investigate your claim, explain your legal options and aggressively pursue justice on your behalf and litigate aggressively against the insurance companies with the intention of holding them accountable for every dollar our clients deserve. Settlement is n...

Data entry options for an array using goto statement

Image
 Data entry options for an array using goto statement: //Multiple Input and output options for an array #include<iostream> using namespace std; void main() { int arr[5]; int option,i; int counter=0; xyz: cout<<"press 1, input"<<endl; cout<<"press 2, output"<<endl; cout<<"press 3, reverse"<<endl; cout<<"press 4, to multiply data by 3"<<endl; cout<<"press 5, addition"<<endl; cin>>option; if(option==1) //input { cout<<"Enter the values of array"<<endl; for(i=0;i<5;i++) { cin>>arr[i]; } counter=counter+1; } else if(option==2) { if(counter==0) { cout<<"Firstly enter the array data"<<endl; goto xyz; }    //output for(i=0;i<5;i++) { cout<<arr[i]<<" "; } cout...

Duplicate values removal from array

Image
Duplicate values removal  from array: //removal duplicate values from array  #include<iostream> using namespace std; void main() { int a[8]={1,2,3,3,4,1,2,1}; int b[8]={0,0,0,0,0,0,0,0}; b[0]=a[0]; for(int i=1;i<8;i++) { int counter=0; for(int j=0;j<i;j++) { if(a[i]==b[j]) counter++; } if(counter>0) b[i]=0; else b[i]=a[i]; } for(int k=0;k<8;k++) { if(b[k]!=0) cout<<b[k]<<" "; } cout<<endl; } Download: To download this code click on the given link below: Download

Table sorting using pointers

Image
Table sorting using pointers: //Data Sorting of Table(order 5x5) using Pointers #include<iostream> using namespace std; void main() { int a[5][5]={{20,17,19,16,18},{24,25,21,23,22},{11,15,14,12,13},{9,8,7,6,10},{5,2,3,1,4}}; int *b; int temp; for(int i=0;i<25;i++)//loop to repeat sorting mechanism { b=&a[0][0]; for(int j=0;j<24;j++) { if(*b>*(b+1)) { temp=*b; *b=*(b+1); *(b+1)=temp; } b++; } } //To output sorted elements for(int m=0;m<5;m++) { for(int n=0;n<5;n++) { cout<<a[m][n]<<" "; } cout<<endl; } } Download: To download this code click on the given link below: Download

Table sorting by converting data into 1 D array

Image
Table sorting by converting data into 1 D array: //Data Sorting of Table(order 5x5) by converting array Data into 1-D array #include<iostream> using namespace std; void main() { int a[5][5]={{20,17,19,16,18},{24,25,21,23,22},{11,15,14,12,13},{9,8,7,6,10},{5,2,3,1,4}}; int b[25]; int k=0; int temp; //conversion of 2D array into 1D array for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { b[k]=a[i][j]; k++; } } //sorting mechanism int m,n; for(n=0;n<25;n++)//loop to repeat sorting mechanism { for(m=0;m<24;m++) { if(b[m]>b[m+1]) { temp=b[m]; b[m]=b[m+1]; b[m+1]=temp; } } } //To output sorted elements for(m=0;m<25;m++) { if(m%5==0 && m>1) cout<<endl; cout<<b[m]<<" "; } cout<<endl; } Download: To download this program click on the given link below: Download

Table sorting using 2D array

Image
Table sorting using 2d array: //Data Sorting of Table(order 5x5) using 2-D array #include<iostream> using namespace std; void main() { int a[5][5]={{20,17,19,16,18},{24,25,21,23,22},{11,15,14,12,13},{9,8,7,6,10},{5,2,3,1,4}}; int temp; for(int k=0;k<25;k++)//to repeat sorting mechanism { for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { if(j<4) { if(a[i][j]>a[i][j+1]) { temp=a[i][j]; a[i][j]=a[i][j+1]; a[i][j+1]=temp; } } else if(j==4 && i<4) { if(a[i][4]>a[i+1][0]) { temp=a[i][4]; a[i][4]=a[i+1][0]; a[i+1][0]=temp; } } } } } //To output sorted elements for(int m=0;m<5;m++) { for(int n=0;n<5;n++) { cout<<a[m][n]<<" "; } cout<<endl; } } Download: To download this code click on the given link below: Download

Mark wise sorting of the given data

Image
Mark wise sorting of the given data: /*Marks-wise Sorting of Given Data Reg# Name Marks  1 Ahmed 5  2 Bilal 9  3 Ali 4  4 Daud 10  5 Umer 6 */ #include<iostream> using namespace std; void main() { int a[5][2]={{1,5},{2,9},{3,4}, {4,10},{5,6}}; int temp,temp1,z; char temp2; char b[5][10]={{'A','H','M','E','D'}, {'B','I','L','A','L'}, {'A','L','I'}, {'D','A','U','D'}, {'U','M','E','R'}}; for(int j=0;j<4;j++) { for(int i=0;i<4;i++) { if(a[i][1]<a[i+1][1]) { temp=a[i][1];// for marks sorting a[i][1]=a[i+1][1]; a[i+1][1]=temp; temp1=a[i][0];// reg no sorting  a[i][0]=a[i+1][0]; a[i+1][0]=temp1; for(z=0;z<10;z++) ...

Hypotenuse calculation of triangle using user defined functions

Image
Hypotenuse calculation using user defined functions: // Find Hypotenuse #include<iostream> #include<cmath> using namespace std; double hypotenuse(double a, double b); void main() { double side1, side2; cout << "Enter First Side : "; cin >> side1; cout << "Enter Second Side : "; cin >> side2; cout << endl; cout << "Hypotenuse : " << hypotenuse(side1,side2); cout << endl; } double hypotenuse(double a, double b) { double c; c = sqrt(pow(a,2) + pow(b,2)); return c; } Download: To download this code click on the given link below, also bookmark this website for more informative content. Download

Distance between two points using user defined functions

Image
Distance between two points using user defined functions: To calculate the distance between two points by using user defined function's code is given below: Code: // Find the Distance between points. #include<iostream> #include<cmath> using namespace std; double distance(double x1, double x2, double y1, double y2); void main() { double x1, x2, y1, y2; cout << "Enter X1: "; cin >> x1; cout << "Enter X2: "; cin >> x2; cout << "Enter Y1: "; cin >> y1; cout << "Enter Y2: "; cin >> y2; cout << endl; cout << "Distance : " << distance(x1, x2, y1, y2); cout << endl; } double distance(double x1, double x2, double y1, double y2) { double distance; distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); return distance; } Download: To download this code click on the ...