You are on page 1of 5
12119721, 8:09 PM hhtps:lwawskllrack comfacesicandidatelabcodeprograms.xhimI7type=LAB Webinar /Other Programming Track(s) ‘View Completed Lab Tracks Unary Operator Overloading - class tance (Id-13671) The program must accept a distance in feet and inches, The program must add 1 inch to the given distance and print the revised distance. Then the program must add 1 inch to the revised distance and print the revised distance. Your task is to define the class Distance so that the program runs successfully, Example Input/Output 1: Input: 29 Output 210 an Example Input/Output 2: Input: an Output 50 51 Show My Solution hitpsiwow.skirack conviaces/candidat/labcodeprograms xhimI?iypa=LAS 1s 12119721, 8:09 PM hhtps:lwawskllrack comfacesicandidatelabcodeprograms.xhimI7type=LAB #include using namespace std; class Distance « int feet, inches; public: Distance(){} Distance(int #,int i) { feet= 1) inches=i; x void display() { coutc< (Feet rinches/12)<« coutccinchest12<> feet >> inches; Distance distance(feet, inches); +Hdistance; distance.display(); s4distance; distance.display(); return @5

using namespace std; class Student { int marks public: void setMarks(int m) int getMarks() { return mark; + friend Student operator + (Student &s1,Student &s2) { Students; 1. getMarks()+s2.getMarks()5 h int main() int ma, 25 cin >> mi >> 23 Student studi, stud2s studi. setMarks (m1); stud2.setMarks (m2); Student stud3 = studl + stud2s cout << stud3.getMarks(); return 0; {> Sum of Two Distances (Id-13859) hitpsiwow.skirack conviaces/candidat/labcodeprograms xhimI?iypa=LAS hips slwww slack comfacesicandidatelabcodeprograms xhtml 7type=LAB a8 12119721, 8:09 PM hhtps:lwawskllrack comfacesicandidatelabcodeprograms.xhimI7type=LAB The program must accept two distances(in feet and inches) as the input. The program must print the sum of the two distancestin feet and inches) as the output. Please fill in the missing lines of code by defining the class Distance so that the program runs successfully. Formula: 1 Foot = 12 Inches Input Format: The first line contains two integers representing the feet and inches of the distance 1 The second line contains two integers representing the feet and inches of the distance 2. Output Format: The first line contains two integers representing the feet and inches of the sum of the two distances. Example Input/Output 1: Input: 2210 Bn Output: 469 Explanation: Distance 1 = 22 feet and 10 inches, Distance 2 = 23 feet and 11 inches, The sum of the two distances is 46 feet and 9 inches. Example Input/Output 2: Input: 158 "4 Output: 270 Show My Solution hitpsiwow.skirack conviaces/candidat/labcodeprograms xhimI?iypa=LAS 46 12119721, 8:09 PM hhtps:lwawskllrack comfacesicandidatelabcodeprograms.xhimI7type=LAB #include using namespace std; class Distance « int feet,inches; public void setFeet(int #) { feet=f; } void setInches(int i) « inches=is y int getFeet() { return feet; y int getinches() { return inches; + Distance operator+(Distance &d) « Distance di; int xeinches#d.inches; di. feet=feet+d.feet+x/12; di.inches=x¥i2; return di } h int main() « int feet, inches; cin >> feet >> inches; Distance di; di.setreet (feet); d1.setInches(inches); cin >> feet >> inches; Distance 42; d2.setFeet (Feet); d2.setInches(inches) 5 Distance d3 = di + d25 cout << d3.getFeet() <<" " << d3.getInches(); return @; y hitpsiwow.skirack conviaces/candidat/labcodeprograms xhimI?iypa=LAS 55

You might also like