Question

In: Computer Science

In C++!!!! What do you do if you need to copy a 560x400mm image onto a...

In C++!!!!

What do you do if you need to copy a 560x400mm image onto a standard sheet of US letter-size paper (which is about 216x280mm), while keeping the image as large as possible? You can rotate the image 90 degrees (so that it is in "landscape" mode), then reduce it to 50% of its original size so that it is 200x280mm. Then it will fit on the paper without overlapping any edges. Your job is to solve this problem in general.

Input: The input consists of one or more test cases, each of which is a single line containing four positive integers A, B, C, and D, separated by a space, representing an AxBmm image and a CxDmm piece of paper. All inputs will be less than one thousand. Following the test cases is a line containing four zeros that signals the end of the input.

Output: For each test case, if the image fits on the sheet of paper without changing its size (but rotating it if necessary), then the output is 100%. If the image must be reduced in order to fit, the output is the largest integer percentage of its original size that will fit (rotating it if necessary). Output the percentage exactly as shown in the examples below. You can assume that no image will need to be reduced to less than 1% of its original size, so the answer will always be an integer percentage between 1% and 100%, inclusive.

Example:

Example input: Example output:
560 400 218 280 50%
10 25 88 10 100%
8 13 5 1 12%
9 13 10 6 66%
199 333 40 2 1%
75 90 218 280 100%
999 99 1 10 1%

0 0 0 0

Solutions

Expert Solution

Hey there. This code will help you.

#include <iostream>
using namespace std;
int main(){

while(true)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
if(a==0 && b==0 && c==0 && d==0)
break;

//Finding which of the two dimensions of the paper is greater
int lengthOfpaper, widthOfpaper;
if(c>d)
{
lengthOfpaper=c;
widthOfpaper=d;
}
else
{
lengthOfpaper=d;
widthOfpaper=c;
}
//Now it is ensured that lengthOfpaper has the greater value

//Similarly, we will do for the image

int lengthOfImage, widthOfImage;

if(a>b)
{
lengthOfImage=a;
widthOfImage=b;
}
else
{
lengthOfImage=b;
widthOfImage=a;
}

//Now it is ensured that lengthOfImage has the greater value.

//If the image needs to be rotated, the lengthOfImage having the greater value, will ensure it.

int lengthPercentage, widthPercentage; //To store percentage reduction required in length and width

//Calculating reduction required in length and width
lengthPercentage=(lengthOfpaper*100)/lengthOfImage;
widthPercentage=(widthOfpaper*100)/widthOfImage;

//Assigning the smaller value of the reduction to the answer variable, because if it fits in, larger one will surely fit in.
int reduction= lengthPercentage<widthPercentage? lengthPercentage:widthPercentage;

if(reduction>100) //Reduction can not be more than 100%.
reduction=100;

cout<<reduction<<"%"<<endl;
}

}

What I've done is stored the larger dimension in length variable while smaller one in width variable. This will ensure that there is optimal rotation.

Then I've found ratio of both the dimensions and print the higher reduction value. Please note that, the smaller the numerical value stored in reduction variable, the higher the reduction is. The higher reduction will ensure that both dimensions completely fit.

Here's sample output :


Related Solutions

What can you do as a nursing student to promote a positive image for nursing?
What can you do as a nursing student to promote a positive image for nursing?
I need a fresh answer. Do not copy and paste. Solve only when you have deep...
I need a fresh answer. Do not copy and paste. Solve only when you have deep subject knowledge,. Thank You Please answer the question below. prepare the journal entries for all the following related transaction (all occurring within the current year). Assume all depletion and amoritization for the full year. Also, assume all purchases were made with cash. A. An exploration company purchased land with a valuable ore deposit      Estimated ore available in the deposit (in tons)                      4,700,000     ...
C(Q1, Q2) = 3,500 - 205Q1Q2 - (Q1)2 + (Q2)2 A. What do you need to...
C(Q1, Q2) = 3,500 - 205Q1Q2 - (Q1)2 + (Q2)2 A. What do you need to know from the equation above to see if there are Cost Complementarity? Are there Cost Complementarity? B. What is MC1(Q1,Q2) ? C. What is MC2(Q1,Q2) ? D. Are there economies of scope? Explain. E. What are the implications for a merger?
(C++) I need to Create a Copy function of a Binary Search Tree recursively providing these...
(C++) I need to Create a Copy function of a Binary Search Tree recursively providing these structure emplate <typename T> class Tree {    struct TreeNode    {        T mData;        TreeNode* mLeft = nullptr;        TreeNode* mRight = nullptr;        TreeNode* mParent = nullptr;        bool mIsDead = false;        TreeNode()        {        }        TreeNode(T tData) : TreeNode()        {            mData = tData;...
Here is the name of the article you need to use, you can copy and paste...
Here is the name of the article you need to use, you can copy and paste it and it will come right away: They Said Seattle’s Higher Base Pay Would Hurt Workers. Why Did They Flip? 1) Briefly summarize the main points of the article 2) Who benefitted from the minimum wage increase? Who was made worse off? 3)Explain how the researchers reconciled their old results with their new results. 4) How convinced are you that the researchers isolated the...
hi i need to do a C++ program. You are going to practice the use of...
hi i need to do a C++ program. You are going to practice the use of array by implementing the interface of Shuttle Puzzle. Here is an example of how you play the Shuttle Puzzle. Say that you start with a board with 7 holes and there are 3 black and 3 white marbles on the board in this configuration: W W W . B B B The dot (.) represents the empty hole withouth any marble. The objective of...
You need to apply multiple photoshop techniques on an image. The following techniques to be applied:...
You need to apply multiple photoshop techniques on an image. The following techniques to be applied: Image retouching Image stretching and equify technique Changing background (white) The above techniques need to be applied to an image with a person. You can have as many layers as you need but keep the original image layer at bottom so that it can be compared with the edited image.
How do you start responding to others? What do you need to look for in a...
How do you start responding to others? What do you need to look for in a response?
Phase IV – What Evidence Do You Need? Describe precisely what evidence you would need to...
Phase IV – What Evidence Do You Need? Describe precisely what evidence you would need to collect in order to answer the research question of, Are large craters on Venus typically more degraded than small craters?6)Create a detailed, step-by-step description of evidence that needs to be collected and a complete explanation of how this could be done—not just look and see when the region returns to the same point, but exactly what would someone need to do, step-by-step, to accomplish...
Explain the Need and importance of understanding International Political Economy. (Please do not copy and paste...
Explain the Need and importance of understanding International Political Economy. (Please do not copy and paste from the internet. Would be grateful if you could also include a couple of in-text citations from a journal or a book)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT