Microsoft Visual C#
7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Cengage Learning,
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 3E
Choose the best data type for each of the following, so that no memory storage is wasted. Give an example of a typical value that would be held by the variable, and explain why you chose the type you did.
- the number of years of school you have completed
- your final grade in this class
- the population of China
- the number of passengers on an airline flight
- one player’s score in a Scrabble game
- the number of Electoral College votes received by a U.S. presidential candidate
- the number of days with below freezing temperatures in a winter in Miami, Florida
- one team’s score in a Major League Baseball game
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
i. Explain the following datatypes in your own words without copying it from
anywhere.
a. int
b. float.
c. double.
d. string.
e. Bool.
ii. Write a program in C++ with the following datatypes. Use the 3 different variables
with the same data type. Explain the codes step by step.
a. int
b. float.
c. double.
d. string.
e. bool.
Calculate and return the sum of two decimal numbers - getSum.
Given the radius of a circle, print the area of a circle - printArea.
Given a student’s name and three test scores (of type int), print the student’s name and average test score - printStudentDetails.
Compute and return the average speed of a car, given the distance traveled (as type double) and traveling time (in hours and minutes, both of type int) - getAverageSpeed. *
Here is the question:
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.
Here is the code given:
// Program displays some facts about a string
public classDebugSeven3
{
public static void main(String[] args)
{
String quote =
"Honesty is the first chapter in the book of wisdom. - Thomas Jefferson";
System.out.println("index.of('f') is: " + quoteindexOf('f'));
System.out.println("index.of('x') is: " + quoteindexOf('x'));
System.out.println("char.At(5) is: " + quote.charAt(50));
System.out.println("endsWith(\"daughter\") is: " + quote.endsWith("daughter"));
System.out.println("endsWith(\"son\") is: " + quote.endsWith("son"));
System.out.println("replace('e', '*') is: ", quote.replace('e', '*'));
}
}
Chapter 2 Solutions
Microsoft Visual C#
Ch. 2 - Prob. 1RQCh. 2 - Prob. 2RQCh. 2 - Prob. 3RQCh. 2 - Assume that you have two variables declared as int...Ch. 2 - Assume that you have a variable declared as...Ch. 2 - Assume that you have a variable declared as int...Ch. 2 - Assume that you have a variable declared as int...Ch. 2 - Prob. 8RQCh. 2 - Assume that you have a variable declared as int...Ch. 2 - Assume that you have a variable declared as int...
Ch. 2 - Prob. 11RQCh. 2 - Which of the following is not a C# comparison...Ch. 2 - Prob. 13RQCh. 2 - Which of the following C# types cannot contain...Ch. 2 - Assume that you have declared a variable as double...Ch. 2 - Assume that you have declared a variable as double...Ch. 2 - When you perform arithmetic operations with...Ch. 2 - Prob. 18RQCh. 2 - Prob. 19RQCh. 2 - Which of the following compares two string...Ch. 2 - What is the numeric value of each of the following...Ch. 2 - What is the value of each of the following Boolean...Ch. 2 - Choose the best data type for each of the...Ch. 2 - In this chapter, you learned that although a...Ch. 2 - Write a C# program named InchesTOCentmeters that...Ch. 2 - Prob. 6ECh. 2 - Write a C# program named ProjectedRaises that...Ch. 2 - Convert the ProjectedRaises class to an...Ch. 2 - Malcolm Movers charges a base rate of $200 per...Ch. 2 - Prob. 10ECh. 2 - Write a program named Eggs that declares four...Ch. 2 - Modify the Eggs program to create a new one named...Ch. 2 - Write a program named MakeChange that calculates...Ch. 2 - Write a program named Testslnteractive that...Ch. 2 - Write a program named FahrenheitToCelsius that...Ch. 2 - Prob. 16ECh. 2 - Prob. 17ECh. 2 - Pig Latin is a nonsense language. To create a word...Ch. 2 - Each of the following files in the Chapter.02...Ch. 2 - In Chapter 1, you created two programs to display...Ch. 2 - Prob. 2CP
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- You are writing a python program that will take as input a home type, a length, and a width. Home types are: "trailer", "bungalow", "two-storey" Home type: bungalow Lengths are from 20 feet to 72 feet (real estate still tends to use imperial measures) Length: 48 Widths are from 8 feet to 27 feet Width: 27 From this, you are to generate an insurance report (example printed line): You are insuring a bungalow of 1296 square feet. If any of the data is invalid (less than the minimum or maximum, or not one of the defined types) then you should print: ***INVALID DATA*** Note, however, if you are dealing with a trailer, you have to also check the following: If the trailer is 40 feet in length or less, you are insuring it as a travel trailer, so your output might look like: You are insuring a travel trailer of 320 square feet. If it is more than 40 feet in length, it will look like this: You are insuring a mobile home of 1152 square feet. Remember, a two-storey has double…arrow_forwardyou are required to write a universal calculator that HALFs that value of the different types of data. Especially, the calculator must take the following types of input.1. a decimal number2. a float point number3. a binary number which must be prefixed with "0b" (e.g. 0b111, 0b1010 are valid. 01b1010, ob101, 01010 are invalid)4. a hexadecimal number which must be prefixed with "0x" (e.g. 0x19, 0xAA are valid. 01x1A, ox1A, 01A are invalid) Please note that:Your program must implement function overloading. You can consider the examples below for your implementation. You are provided with the initial code which can be found. The initial code has already checked different types of input for you.arrow_forwardWhy am I getting errors? Says "Index 0 out of bounds for length 0" I didn't specify when I asked this question last time, the program needs: write a program that takes two double command line arguments representing the sides of a rectangle. The program should then call a void function that reports the area of the rectangle accurate to three decimal places public static void main(String[] args) { System.out.println("Enter length and width of rectangle"); for (int i=0; i < args.length; i++) { System.out.println(args[i]); } Double area= Double.parseDouble (args[0]) * Double.parseDouble (args[1]); System.out.println(" Area of rectangle is :" + String.format("%.3f", area)); } }arrow_forward
- Here is the question: The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Here is the code given: // Program prompts user to enter a series of integers // separated by spaces // Program converts them to numbers and sums them import java.util.*; public class DebugSeven2 { public static void main(String[] args) { String str; int x; int length; int start; int num; int lastSpace = -1; int sum = 0; String partStr; Scanner in = new Scanner(System.in); System.out.print("Enter a series of integers separated by spaces >> "); str = in.nextLine(); length = str.length(); for(x = 0; x <= length; ++x) { if(str.charAt(x) == ' ') { partStr = str.substring(lastSpace + 1); num =…arrow_forwardSuppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate the amount that you will have after a specific number of months. The formula, which is known as the future value formula, is:F=P×(1+i)tThe terms in the formula are as follows:o F is the future value of the account after the specified time period.o P is the present value of the account.o i is the monthly interest rate.o t is the number of months.Write a program that prompts the user to enter the account’s present value, monthly interest rate, and the number of months that the money will be left in the account. The program should pass these values to a function named futureValue that returns the future value of the account, after the specified number of months. The program should display the account’s future value. i attached the screenshot of the output so the output should look like that.arrow_forwardYou can find out how many seconds have elapsed since Jan 1, 1970 using the time() function. #include <time.h> now = time(NULL); // now is more than a billion seconds (which data type should you use?) Write a program that estimates how many years, months, weeks, days, and hours have gone by since Jan 1 1970 by calculations with the number of seconds that have passed. The number of months must be less than 12, i.e., take out how many years have gone by first, then how many months are left, then weeks, etc. Assume that all years have 365 days, and all months have 30.42 days. Don’t use a calculator, or any web site that reports the number of seconds in a month, etc. – your C program can calculate anything that you need. Notice that this is an assignment on using arithmetic in C. Hints. How many seconds are in a minute? hour? A day? A week? A month? A year?arrow_forward
- Consider the following code fragment, where the variable letter contains an uppercase letter: if 'A' <= letter <= 'U':...print("You entered a vowel")else:...print("The letter is not a vowel") Based on the ordering of characters in the ASCII table, which of the following statements is not true about this code? Select one: a. Prints You entered a vowel for all vowels b. Prints You entered a vowel for all vowels and all consonants. c. Prints You entered a vowel for some consonants. d. Prints The letter is not a vowel for some consonants.arrow_forwardCreate a program (using Java or Python) for converting binary numbers to decimal numbers, and conversely. [You can not use the conversion functions from the mathematical library.] Your program should do the following: Ask the user if they want a Binary number converted to Decimal number, a Decimal number converted to a Binary number, or to quit the program. Ask the user for the number, take the appropriate action and then print out the appropriate message.arrow_forwardPlease do this in Python Programming and provide Screenshots The output should be exact same like in the examples. If the output in the example is in 2 decimals, then it should be like that. 1c - Othello 1 Othello, is a 2-player deterministic (no use of dice), perfect information (no information only known to one of the players) board game, similar to chess or go. The goal of this assignment is to give some information about the outcome once an Othello game has finished. This information is obtained by two measurements: The percentage of black pieces of all the pieces on the board. The percentage of the board that is covered in black pieces. The Othello board measures eight squares by eight squares, making the total number of squares sixty-four. Write a program that takes the number of white pieces followed by the number of black pieces as input. Print the two percentages as output. Enter the number of white pieces on the board: 34Enter the number of black pieces on the board:…arrow_forward
- Write a program that asks users when their birthday is. Use information provided to give them their astrological sign. Each of the twelve signs should display a different horoscope. Use the following dates for each sign, keeping in mind that both month and day must be evaluated for an accurate result. Aries: March 21–April 20 Taurus: April 21–May 21 Gemini: May 22–June 21 Cancer: June 22–July 22 Leo: July 23–August 22 Virgo: August 23–September 23 Libra: September 24–October 23 Scorpio: October 24–November 22 Sagittarius: November 23–December 21 Capricorn: December 22–January 20 Aquarius: January 21–February 19 Pisces: February 20–March 20arrow_forwardWrite a program that calculates and prints the take-home pay for a commissioned sales employee. Perform a compile-time initialization andstore the name of Joshua Montain in a variable called employeeName.For practice working with the decimal data type, declare all monetaryvalues as decimal. Employees earn 7% of their total sales as a commission. Employees pay federal tax rate of 18%. All employees contribute10% of their earnings to a retirement program and pay an additional6% of their earnings to Social Security. If Joshua’s sales this month were$161,432, how much money will he take home? Produce a formatted report with your values labeled and number aligned showing theamount for each of the computed items and the sales commission percentage rate. Also show the total deductions. The final take home payand total sales figure used for the calculations should be formatted withcurrency. All other values should have comma separators, no dollar sign,and display two positions to the right of…arrow_forwardDevelop a program that takes a set of pairs of data values (e.g. sales and month), fits a straight line to the data, and displays the results in a table and chart. Fitting a line or equation to data is done in many fields including business and scientific research. __________________________________________________________ #include <iostream> // Needed for cout and cin#include <iomanip> // Needed for setw and others#include <fstream> // Needed for ifstream#include <string> // Needed for string data type#include <cmath> // Needed for pow #include "Graph.h" // Used to graph the results using namespace std; // To use cout instead of std::cout // Function prototypesbool readArrays(ifstream& inFile, double x[], double y[], int size); int main() { // Do "Press return to continue..." on exit atexit([] {system("pause"); }); // Prompt for the name of the data file and store it in a string variable named fileName. // Put your code…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Computer Programming for Beginners | Functions, Parameters & Arguments | Ep24; Author: Programming With Avelx;https://www.youtube.com/watch?v=VXlh-qJpfw0;License: Standard YouTube License, CC-BY