Wednesday, February 12, 2014

conversionApp

CMPS 1043 - Program #1

Measurement Conversion

Write a C++ program to convert a measurement given in feet to the equivalent number of (a)
yards, (b) inches, (c) centimeters, and (d) meters. Input the number of feet from the keyboard and print the equivalent measures into a file as shown below.

1 ft. = 12 in.     1 yd. = 3 ft.     1 in. = 2.54 cm.     1 m. = 100 cm.

OUTPUT

2.00000 feet equals //this section will be repeated for each of the 10 data items
0.6667 yards
24 inches
60.96 centimeters
0.6096 meters

Use type double for all variables. Be sure to put in prompts asking for data.
Use the following main function to cause the program to execute 10 times for different data
values. Check your output, making sure your answers are correct. Comment your program as discussed in class.

int main (void)
{
          int count;
          ........PUT YOUR DECLARATIONS HERE.........
         count = 1;
         while (count <= 10)
                  {... PUT YOUR STATEMENTS HERE...
                  count = count + 1;
                   }
          return 0;
}

Use the following data to enter into the keyboard:
2         39.209   3            100.0    78.921
86.5    10          34912    45.88    87.09


package graceApp;
 
import java.text.*;
import java.util.Scanner;
 
public class graceApp {
 
 public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
 
  double feet;
  DecimalFormat df = new DecimalFormat("#.##");
  System.out.println("This program will run 5 times before it quits...");
  System.out.println("");
 
  for (int i = 1; i <= 10; i++) {
   System.out.print("Please enter amount of feet: ");
   feet = input.nextDouble();
 
   double yards = feet / 3;
   double inches = feet * 12;
   double centimeters = feet * 30.48;
   double meters = feet / 30.48;
 
   System.out.println(df.format(yards)+ "yd  "+ (df.format(inches) + "in  " + (df.format(centimeters)+ "cm  " + (df.format(meters) + "m  "))));
   System.out.println("");
 
  }
 }
}

No comments:

Post a Comment