0% found this document useful (0 votes)
12 views

Assignment 02

The document provides instructions for Assignment 2 in COMP100 Programming Fundamentals. Students are asked to complete exercises using different data types in C# including int, double, char, bool, and string. The exercises involve reading input from the user and displaying output. Students must use interpolated expressions and format specifiers where necessary. Six exercises are described that involve reading various data types from user input and performing calculations.

Uploaded by

Wisecrack 34
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment 02

The document provides instructions for Assignment 2 in COMP100 Programming Fundamentals. Students are asked to complete exercises using different data types in C# including int, double, char, bool, and string. The exercises involve reading input from the user and displaying output. Students must use interpolated expressions and format specifiers where necessary. Six exercises are described that involve reading various data types from user input and performing calculations.

Uploaded by

Wisecrack 34
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

COMP100 Programming Fundamentals Week 3

Exercise using different data-types


Assignment 2 – Due in Week 4
Once you are done with your programs, upload them to eCentennial under
Assessments / Assignment / Assignment 2

The objective of these exercises is to read and display the five native data types (int, double,
char, bool and string). Please note that some of the problems might not have an intelligent
business purpose, but all that is necessary is to for you to read from user input from the
keyboard and display program output to the.

You are reminded about the coding practices that


should be adhered to for this course regarding An interpolated string is a string literal that
solution name, project name, identifiers and also might contain interpolated expressions.
When an interpolated string is resolved to a
pasting a copy of the problem at the top of your c# result string, items with interpolated
file. expressions are replaced by the string
representations of the expression results.
You MUST use interpolated expression and where
necessary format specifier.

1. Write a program to prompt the user to enter a single


Use the Convert.ToChar()
character. The program should display a message like
method to obtain a char from
“Your response was y”. For this question, you must use
an input.
a variable of type char.

2. Write a program to ask the user about the validity of a


Use the
simple statement. The program should accept the
Convert.ToBoolean()
response then display the statement as well as the
method to obtain a bool from
response. The response should be true or false. For this
an input.
question, you must use a variable of type bool. It is
useful to know that Convert.ToBoolean() can work with true, True, tRue, TRUE etc.

3. Write a program to calculate the area of a circle. The


Use the
user will enter the radius of the circle and the program Convert.ToDouble()
will calculate and display the area according to the
method to obtain a double
formula (area = 3.14 * radius * radius). You must accept
from an input.
fractions as the input. If the user enters 1.2 for the
radius then the area will be 4.52. (Use the "F" format-specifier for floating point values).

Data Types
COMP100 Programming Fundamentals Week 3

4. Write a program that prompts the user for a number


Use the appropriate method
(that may be a fraction). The program reads in the input
of the Convert class
and print the following: the input as a double, the input
as an int and finally the input as a char.
e.g. if the input is 65.790, then the output will be 65.790, 65, and A.

5. Adult ticket cost $3.75 and child ticket cost $2.25. Write a program to prompt the user for
the amount of adult and child ticket that she needs. The program will display a user-friendly
message of the number of tickets brought as well as the total cost. (Use the "C" format-
string for currency).

6. Write a program to calculate and display the potential difference between the ends of a
wire. The program will prompt the user for the current flowing and the resistance of the
wire. Potential difference is the product of the current and the resistance of the wire and
may include a fractional part. (Again, use the "F" format-specifier for floating point values).

Data Types

You might also like