Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

C++ program to display the distance in feet and inches

YASH PAL, 31 July 202422 August 2024

In this post we will write a C++ program to display the distance in feet and inches. 

C++ program to display the distance in feet and inches

C++ program to display the distance in feet and inches.

#include<iostream>
#include<conio.h>

class distance
{
    private:
        int feet;
        float inches;
    public:
        distance()
        {
            feet = 0;
            inches = 0.0;
        }
        distance(int ft, float in)
        {
            feet = ft;
            inches = in;
        }
        void input()
        {
            std::cout<<"Ente the feet = ";
            std::cin>>feet;
            std::cout<<"Enter the inches = ";
            std::cin>>inches;
        }
        void show()
        {
            std::cout<<feet<<"t"<<inches<<std::endl;
        }
        distance adddis(distance d2);
};

int main()
{
    system("cls");

    distance dis1, dis3;
    distance dis2(11,6.5);
    dis1.input();
    dis3 = dis1.adddis(dis2);

    std::cout<<"distance one = ";

    dis1.show();

    std::cout<<"distance two = ";

    dis2.show();

    std::cout<<"distance three = ";

    dis3.show();

    getch();
}

distance distance::adddis(distance d2)
{
    distance temp;
    temp.inches = inches+d2.inches;
    temp.feet = d2.feet;

    return(temp);
}

Output

Enter the feet = 5
Enter the inches = 2.8
distance one = 5    2.8
distance two = 11   6.5
distance three = 16     9.3
C++ Programming Tutorials coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes