program logic:
program:
#include <iostream>
using namespace std;
class Distance{
int feet;
int inches;
public:
Distance(int f, int i){
feet = f;
inches = i;
}
void getData(){
cout<<"Enter Value of feets
:";
cin>>feet;
cout<<"Enter Value of inches
:";
cin>>inches;
}
void display(){
cout<<"\tFeets:
"<<feet<<"\n";
cout<<"\tInches:
"<<inches<<"\n";
}
Distance operator +(Distance D){
int f = this->feet + D.feet +
(this->inches+D.inches)/12;
int i = (this->inches +
D.inches)%12;
return Distance(f,i);
}
};
int main(){
Distance d1(0,0),d2(0,0);
cout<<"Enter Distance1:\n";
d1.getData();
cout<<"Enter Distance2:\n";
d2.getData();
Distance d3 = d1+d2;
cout<<"Distance1: \n";
d1.display();
cout<<"Distance2: \n";
d2.display();
cout<<"Distance3: \n";
d3.display();
}
output:
Question 14 10 pts Using c++ class and objects, write a c++ program to read and...
C++ program Create a class Time having data members HH, MM, SS of type integer. Write a C++ program to do the following: 1. Use a Constructor to initialize HH, MM, SS to 0. 2. Create two Objects of this class and read the values of HH, MM, SS from the user for both objects (Using proper member functions). 3. Use a binary + operator to add these two objects created (Store & display result using separate object). 4. Use...
Define a C++ class managing objects using a
Linked List.
(10 points) Define a C++ class named "BirthdayList" that manages a list of Birthday objects as a linked list maintaining the order of entry (first birthday should be displayed first). Write a main function to show that you can add a list of birthdays and print out that list in the order that you have entered. (5 points) Add a "search" method into the "BirthdayList" class that accepts a Birthday...
Problem: Write a program to calculate the force of gravitational attraction between two objects of known mass at a known distance. Use the formula developed by Isaac Newton known as Law of Universal Gravitation. F G*m *m2/d2 Where F (Force of gravity) is expressed in Newtons (N), mi and m2 (masses of the objects) are expressed in kilograms (kgs) and d (distance from the center of one object to the center of the other) is expressed in meters (m) and...
The answer need to write in C programming.
QUESTION 2 Write a program using array to generate a multiplication table based on the user's input. For example if user enter 5 as input then a multiply table for 1 to 5 is printed as output as shown in Figure Q2. There are three main steps in this program which are: Print rows (a) (b) Print columns Print multiplication of data inside table (c) Select C:\example1 \bin\Debuglexample 1.exe enter the value...
C++, Visual Studio
(Optional-Extra Credit) Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question Lab 4 Question 2. An AddressBook will allow a person to add, delete, or search for a Person object in the address book 1. The add method should add a person object to the address book .The delete method should remove the specified person object from the address book .The search method that searches the address book...
Write a C++ program for the instructions below. Please
read the instructions carefully and make sure they are followed
correctly.
and please put comment with code!
Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...
using python 3: Program 14: Class with Private Attribute Collection of Objects: modRoom.py Step 1: Create a class called Room as indicated by the UML shown below: Student -length: integer width: integer -height integer -roomNum: integer -roomType: String -room Capacity: integer <<constructor Room (tmpRoomNum:integer tmpRoomType: String, tmpCapacity:integer tmplength: integer, tmpWidth: integer, tmpHeight: integer) +get Length(): Integer +getWidth(): Integer +getHeight(): Integer +get RoomNum(): Integer +getRoom Type(): String +getRoomCapacity(): Integer tRoomType(): String +set +setRoomCapacity(): Integer +calcArea(): Integer +calcSurfaceArea(): nteger +str( String should...
Please use C++,thank you!
Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, or search for a Perso n object in the address book The add method should add a person object to the address book. The delete method should remove the specified person object from the address book 0 .The search method that searches the address book for a specified...
**Program must compile under Ubuntu! (35 pts) Write a C++ program A4p2.cpp with a class of your own design. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called playthat should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var...
c++ help
Write a program that: Creates two finite arrays of size 10 These arrays will serve as a storing mechanism for student grades in Classes A and B Uses a loop to populate the arrays with randomly generated numbers from 0 to 100.These numbers will represent student grades. Compute average grade of each class. Finally, output the two arrays and the message with two averages and best class. ("Class A average is: 65.43; class B average is: 68.90. Class...