Answer to Question #242612 in C++ for frida

Question #242612

How tall a ladder should be so that a person of a given height can place several posters on a wall. All posters are pinned to the wall at a mark located at 75% of the posters’ length. Request the user to enter a person’s height (int) in centimeters. Request the user to enter a list of integers such that each integer represents a poster’s length (cm). Assume the user indicates the end of this list by typing a nonpositive integer. Request the user to enter another list of integers such that each integer represents the height, in centimeters, at which the poster with length should be placed on the wall. Assume the user indicates the end of the list by typing a non-positive integer. If the input lists provided are valid then the program should display how tall a ladder needs to be. Otherwise, the message “Invalid posters data” is displayed. the length of a poster cannot exceed the height of the wall. if no ladder is required to place the posters then the program display zero.


1
Expert's answer
2021-09-27T01:16:47-0400
#include <iostream>
using namespace std;




int main(){
	int personHeight=0;


	int posterLengths[100];
	int posterLength;
	int totalPosterLengths=0;


	int posterHeights[100];
	int posterHeight=1;
	int totalPosterHeights=0;


	//Request the user to enter a person’s height (int) in centimeters. 
	cout<<"Enter a person's height in centimeters: ";
	cin>>personHeight;
	//Request the user to enter a list of integers such that each integer represents a poster’s length (cm). 
	//Assume the user indicates the end of this list by typing a nonpositive integer. 
	posterLength=1;
	cout<<"Enter a list of integers represents a poster's length (cm) (-1 -to exit):\n";
	while(posterLength>0){
		cout<<"Enter a poster's length(cm): ";
		cin>>posterLength;
		if(posterLength>0){
			posterLengths[totalPosterLengths]=posterLength;
			totalPosterLengths++;	
		}
	}
	//Request the user to enter another list of integers such that each integer represents the height, in centimeters, 
	//at which the poster with length should be placed on the wall. 
	//Assume the user indicates the end of the list by typing a non-positive integer. 


	cout<<"Enter a list of integers represents a poster's height (cm) (-1 -to exit):\n";
	while(posterHeight>0){
		cout<<"Enter a poster's height(cm): ";
		cin>>posterHeight;
		if(posterHeight>0){
			posterHeights[totalPosterHeights]=posterHeight;
			totalPosterHeights++;	
		}
	}


	//If the input lists provided are valid then the program should display how tall a ladder needs to be. 
	if(totalPosterLengths==totalPosterHeights){
		if(personHeight<250){
			
			int sum=0;
			for(int i=0;i<totalPosterHeights;i++){
				sum+=posterHeights[i];
			}
			float ladderHeight=personHeight-(sum/totalPosterHeights)*0.75;
			cout<<"Height of the ladder is: "<<ladderHeight<<" centimeters\n";
		}else{
			//if no ladder is required to place the posters then the program display zero.
			cout<<"0";
		}
	}else{
		//Otherwise, the message “Invalid posters data” is displayed. the length of a poster cannot exceed the height of the wall. 
		cout<<"\nInvalid posters data\n";
	}






	cin>>totalPosterLengths;
	return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS