Problem:- C++ Program to Add Two Distances (in inch-feet) System Using structure or C++ program to add two distances using binary plus (+) operator or C++ Program to Add Two Distances in Inch and Feet Using Structures or Write A C++ Program for Returning Objects For Addition Of Distances or C program to Add Two Distances (in inch-feet) - Programming In C/C++ or c++ program to add feet and inches.
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Defining a structure
struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Click This:- C Program For Adding Two Distance Using Structure
Syntax :
struct structure_name
{
//Statements
};
Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.
Solution:-
#include <iostream>
using namespace std;
struct Distance
You May Also See
1. C++ Program To Print All Value Of An Array
2. C++ Program To Print Reverse Order And Print Sum Of Its Element Of An Array
3. C++ Program To Check Evenness / Oddness Of An Array
4. C++ Program To Check Positive / Negative Number Of An Array
5. C++ Program To Check Primeness Of An Array
6. Java Program To Find Greater No. Among given Three Number
7. Java Program For Find The Gross Salary Of An Employee
8. Java Program For Calculate Percentage Of 5 Subjects
9. Java Program For Converting Temperature Celsius Into Fahrenheit
10. Java Program To Display Size Of Different Datatype
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Defining a structure
struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Click This:- C Program For Adding Two Distance Using Structure
Syntax :
struct structure_name
{
//Statements
};
Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.
Solution:-
#include <iostream>
using namespace std;
struct Distance
{
int feet;
float inch;
}d1,d2,sum;
int main()
{
//Ghanendra Yadav
cout << "Enter information for 1st distance" << endl;
cout << "Enter feet: ";
cin >> d1.feet;
cout << "Enter inch: ";
cin >> d1.inch;
cout << endl << "Enter information for 2nd distance" << endl;
cout << "Enter feet: ";
cin >> d2.feet;
cout << "Enter inch: ";
cin >> d2.inch;
sum.feet=d1.feet+d2.feet;
sum.inch=d1.inch+d2.inch;
do
{
sum.inch=sum.inch-12.0;
++sum.feet;
}while(sum.inch>12.0);
cout << endl << "Sum of distances= " << sum.feet << " feet " << sum.inch << " inch";
return 0;
}
Output:-
int feet;
float inch;
}d1,d2,sum;
int main()
{
//Ghanendra Yadav
cout << "Enter information for 1st distance" << endl;
cout << "Enter feet: ";
cin >> d1.feet;
cout << "Enter inch: ";
cin >> d1.inch;
cout << endl << "Enter information for 2nd distance" << endl;
cout << "Enter feet: ";
cin >> d2.feet;
cout << "Enter inch: ";
cin >> d2.inch;
sum.feet=d1.feet+d2.feet;
sum.inch=d1.inch+d2.inch;
do
{
sum.inch=sum.inch-12.0;
++sum.feet;
}while(sum.inch>12.0);
cout << endl << "Sum of distances= " << sum.feet << " feet " << sum.inch << " inch";
return 0;
}
Output:-
You May Also See
1. C++ Program To Print All Value Of An Array
2. C++ Program To Print Reverse Order And Print Sum Of Its Element Of An Array
3. C++ Program To Check Evenness / Oddness Of An Array
4. C++ Program To Check Positive / Negative Number Of An Array
5. C++ Program To Check Primeness Of An Array
6. Java Program To Find Greater No. Among given Three Number
7. Java Program For Find The Gross Salary Of An Employee
8. Java Program For Calculate Percentage Of 5 Subjects
9. Java Program For Converting Temperature Celsius Into Fahrenheit
10. Java Program To Display Size Of Different Datatype
0 Comments: