Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data Structure 4 What is the output of the following code: include using namespace std: #include int main() string s1, s2 (define) cout In operator>

Data Structure image text in transcribed
image text in transcribed
4 What is the output of the following code: include using namespace std: #include int main() string s1, s2 ("define") cout In operator> prompt user to input a date with format dd/mm/yyyy and then use strtok to separate the numbers and assign them to the data members. In operator you need to output the date with format: Jan 5, 2016 (you may define a 6 Write a class named Date which has three private data: day, month, year monthName[ 12]14] to store the short name of months). Then n program to create an object and call cin and cout. You can assume the user will input correct f ormat. Sample output Enter date in format dd/mm/yyyy: 4/12/2015 The date is: Dec. 4, 2015 7 Define a class called Rational for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. Represent rational numbers as two private values of type int, num for the numerator and den for the denominator. The class has a default constructor with default values (mum - 0, den1), a copy constructor, an assignment operator and three friend functions for operator overloading +, > In + operator, the sum of a/b and cid is (a*d+b*c)/bd. In>operator, if the user enter 0 for the denominator, output error message and prompt user to type again (use while loop). In and assign data for them. Then sum the two numbers and display the results. Sample output Enter two integers: 3 0 Error: the denominator cannot be 0. Try again. Enter two integers: 2 3 Enter two integers: 3-4 2/3 + -3/4-1/12 (2 bonus marks) Add a private member function with function prototype void normalize() to normalize the values stored so that, after normalization, the denominator is positive and the numerator and denominator are as small as possible. For example, after normalization 4/-8 would be represented the same as -1/2. You must email me your code for this part

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions