Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The number of lines that can be printed on a paper depends on the paper size, th

ID: 670540 • Letter: T

Question

The number of lines that can be printed on a paper depends on the paper size, the point size of each character in a line, whether lines are double-spaced or single-spaced, the top and bottom margin, and the left and right margins of the paper. Assume that all characters are of the same point size, and all lines are either single-spaced or double-spaced. Note that 1 inch = 72 points. Moreover, assume that the lines are printed along the width of the paper. For example, if the length of the paper is 11 inches and width is 8.5 inches, then the maximum length of a line is 8.5 inches. Write a program that calculates the number of characters in a line and the number of lines that can be printed on a paper based on the following input from the user: (Write for C++ Program Beginner Course)

a. The length and width, in inches, of the paper
b. The top, bottom, left, and right margins
c. The point size of a line
d. If the lines are double-spaced, then double the point size of each character

Explanation / Answer

#include <iostream>
using namespace std;

int main() {
   double length,width,top,bottom,left,right,pointsize;
   int numofchars,numoflines;
   string linetype;

cout<<"Please use space to separate each input: ";
cout<<"Please enter the length and width, in inches, of the paper: ";
cin>>length>>width;
   cout<<"Please enter the top, bottom, left, and right margins,in inches: ";
   cin>>top>>bottom>>left>>right;
   cout<<"Please enter the point size of a line: ";
   cin>>pointsize;
   cout<<"Please enter wheter the line is single-spaced or double-spaced <s> or <d> ";
   cin>>linetype;
  
   while (!(linetype=="s" or linetype=="d")){
   cout<<"Invalid entry. Please enter <s> or <d> ";
   cin>>linetype;
}
   if(linetype=="d")
       pointsize=(pointsize*2);
  
   length=length-(top+bottom);
   width=width-(right+left);
   numofchars=width*72/pointsize;
   numoflines=length*72/pointsize;
   cout<<"The number of characters in a line is: "<<numofchars<<endl;
   cout<<"The number of lines that can be prited on the paper is: "<<numoflines<<endl;

   return 0;
}