C++ examples for Class:object
Create objects for English measurements
#include <iostream> using namespace std; class Measure// w w w . j a v a 2s.c o m { private: int feet; float inches; public: void setdist(int ft, float in) //set Measure to args { feet = ft; inches = in; } void getdist() //get length from user { cout << "\nEnter feet: "; cin >> feet; cout << "Enter inches: "; cin >> inches; } void showdist() { cout << feet << "\'-" << inches << '\"'; } }; int main() { Measure dist1, dist2; dist1.setdist(11, 6.25); //set dist1 dist2.getdist(); //get dist2 from user //display lengths cout << "\ndist1 = "; dist1.showdist(); cout << "\ndist2 = "; dist2.showdist(); cout << endl; return 0; }