Convert Java to C++
Project 2/Project 2.pdf
Introduction to Programming EECS 1500 Project 2 Elementary Aspects of C++
100 Points - Due Thursday February 11 in class The revision is for part a on Modulo division
Note: These projects should be completed by February 4. They are all formally due in class, on Thursday February 11. This later date is only given to help students who enroll late for the class. a. Modulo Division Write a program to read in a 3-digit integer and print out the sum of the digits of the integer. Use the % operator to extrct the digits and use the / operator to extract the digit. Use the following format for input/output:
Enter an integer: 744 The sum of the digits is: 15
b. Approximating Pi Pi can be computed using the formula 4 * (1.0 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - . . .) Write a program to display the result of 4 * (1.0 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13) Note: be sure to use 1.0 not 1 in your program. c. Wind Chill The National Weather Service has a relatively new formula to measure the wind chill temperature. The formula is Wind Chill = 35.74 + 0.6215T - 35.75V0.16 + 0.4275TV0.16
where T = outside temperature (°F) and V = wind velocity (mph). The formula cannot be used for wind speeds below 2 mph, temperatures below -58°F, or temperatures above 41°F. Write a program that prompts the user to enter a temperature and a wind speed, and then displays the wind chill temperature. You may assume the values entered are valid. Enter temperature(Fahrenheit): 5.3 Enter wind speed(mph): 6 The wind chill index is -5
d. Distance Given the two points (x1, y1) and (x2, y2), the distance between these points is given by the formula:
Write a program that prompts the user to enter the two points, and then displays the distance between them. You may assume the values entered are valid. For example, Enter x1 and y1: 1.0 5 Enter x2 and y2: -2.0 1 The distance is 5.0
Project 2/quiz1.txt
package splitter; import java.util.Scanner; public class Split { public static void main(String[] args) { int i = 234; sumDigits(i); } private static void sumDigits(int digits) { System.out.println("digits before calculation: " + digits); int sum = 0; while ( digits > 0 ) { sum += digits % 10; digits /= 10; System.out.println("sum: " + sum); System.out.println("digits after calculation: " + digits); } } }
Project 2/quiz2.txt
package pi; public class Pi { public static void main(String[] args) { double pi; pi=4*((1.0+1/5+1/9+1/13)-(1/3+1/11+1/7)); System.out.print("The Pi is :" +pi); } }
Project 2/quiz3.txt
package temperature; import java.util.Scanner; public class Temperature { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter temperature in Farehneit "); int t = scan.nextInt(); System.out.print("Enter wind Velocity (in MPH) "); int v = scan.nextInt(); if (v>2){ if (t>-58 && t<41){ double WindChill = 35.74+0.6215*t+ Math.pow(0.4275*v,0.16)-Math.pow(35.74*v, 0.16); System.out.print("The temperature is :"+WindChill); } else{ System.out.print("Check the extreme values of temperature"); } } else{ System.out.print("Wind speed cannot be less than 2 mph"); } } }
Project 2/quiz4.txt
package distance; import java.util.Scanner; public class Distance { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter x1 and y1"); double x1 = scan.nextInt(); double y1 = scan.nextInt(); System.out.print("Enter x2 and y2"); double x2 = scan.nextInt(); double y2 = scan.nextInt(); double d = Math.sqrt(Math.pow((x2-x1), 2)+Math.pow((y2-y1), 2)); System.out.print("The distance is "+d) ; } }