Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ENSE504 Introduction to Computing

2022 Assignment 1

C++ Programming


Assignment Value


10% of the total mark for this paper.

Marks will be posted on Canvas as soon as they are all available.


Date and Time Due


11:59 PM, Friday 2 September 2022.


Requirements


This assignment consists of five parts. Write a C++ program for each part with the given specifications and present the screenshot of the output in the report.


Submitting Your Assignment


You must upload a copy of your assignment report, including the C++ program source codes (.cpp) files and related screenshots, to Canvas by 11:59 PM, Friday 2 September 2022.

DO NOT email files to me or give me printed copies of your program.

To make a submission to Canvas:

•   Make a text file copy of your C++ program code for each part:

▪  copy the entire contents of your C++ (cpp) file from Visual Studio for each part

▪   paste the codes into a WORD file (use Word document),

▪  add your comments for the main part of each code

▪  add any screenshots to your report

▪  save the file as "your name_ID number_Assign1" .doc

•   Log in to Canvas and go to the page for this paper.

•  Click on the "Assignments" button.

•  Click on the "Assessment 1" folder.

•  Submit your word file.

•  After uploading the file, click the "Submit" button before leaving Canvas. The upload will not be complete if you do not click the Submit button.

•   You can upload the file more than once (up to three times). I will only receive the last file you upload. This means that if you upload a file and then decide to modify it, you can upload the  modified file, and it will replace the file uploaded earlier.


Plagiarism


I expect students will discuss assignments with each other, but each student is responsible for  producing their work. DO NOT DIRECTLY COPY OTHER PEOPLE'S WORK. The Turnitin        software automatically checks assignment submissions for similarity to other students' work and provides a report of similarities. When plagiarism is detected, disciplinary action may be taken.


Details of marking for this assignment for each part:


40%:   The code is complete and compiled without errors.

10%:   A sufficient number of meaningful code comments.

10%:   Define all variables properly.

20%:   Appropriate use of I/O operations, conditional statements, and string handling. 20%:   Display the code output similar to the provided examples.

Program 1.1 Simultaneous Calculations

[2 marks]

Write a C/C++ program to input two (2) real numbers from the keyboard, with a real value between - 100 and 100 (inclusive).

The program should loop until an appropriate value is entered.

Display the word INVALID whenever an incorrect value is entered.

The value of the first input can be considered as the CURRENT passing through a resistor in a    circuit (in Amps) and the value of the second input as the VOLTAGE across the same resistor  (in Volts).

The program should calculate the value of the resistor (in Ohmes) and display its absolute value (as the resistor should be positive) with three decimal points. Use both "cout" and "printf" in your code to display the results of the calculation with a format similar to the below example:

m3

 

CALCULATE THE RESISTOR OF A CIRCUIT

==================================================

 

Enter CURRENT in Amps between -100 and 100 (inclusive): 120

INVALID

Enter a value between -100 and 100 (inclusive): 24

 

Enter VOLTAGE in Volts between -100 and 100 (inclusive): -230

INVALID

 

Enter a value between -100 and 100 (inclusive): 100

 

====================== The result using cout  ========================

 

The resistor of the circuit with Current of   24.000 Amps, and Voltage of  100.000 Volts is:    4.167 Ohms

 

 

====================== The result using printf  ========================

 

The resistor of the circuit with a Current of   24.000 Amps and Voltage of:  100.000 Volts is:    4.167 Ohms


Program 1.2 Simultaneous Equations                                                             [2 marks]

Write a C/C++ program to calculate values of x and y for angles θ from 0 degrees to 90 degrees (inclusive) in steps of 15 degrees, using the formula:

x = 3cos θ

y = 2sin θ

The cos and sin functions require the angle in radians, and the conversion formula is:

radianS = 

Use both "cout" or "printf" in your code to display the results of the calculation with a format similar to the below example:

CALCULATE THE VALUE OF x and y

=============================

Angle     x=3cosTETA     y=2sinTETA

-------- --------------------------------------


0

15

30

45

60

75

90


3.000

2.898

2.598

2.121

1.500

0.776

0.000


0.000

0.518

1.000

1.414

1.732

1.932

2.000


----------------------------------------------

 


Program 1.3 Find the smallest and largest numbers                                    [2 marks]


A.  Write a C++ program to read EIGHT integer numbers and display the smallest and largest ones.

 

A sample of the program output looks like this example:

Display the smallest and largest

+ + + + + + + + + + + + + + + + + +

Enter 8 integer numbers:

-12

56

123

-345

300

12

-24

135

The Largest Number is: 300

The Smallest Number is: -345

B.  Modify the code in problem 1.3 to warn the user if a non-integer character enters. The code should accept only integer values and have an output similar to the below example:

Display the smallest and largest

+ + + + + + + + + + + + + + + + + +

Enter 8 integer numbers:

345

Enter 7 integer numbers:

567

Enter 6 integer numbers:

-25

Enter 5 integer numbers:

Q

It is not a number! Enter an integer number:

29

Enter 4 integer numbers:

8

Enter 3 integer numbers:

W

It is not a number! Enter an integer number:

123

Enter 2 integer numbers:

0

Enter 1 integer numbers:

560

The Largest Number is: 567

The Smallest Number is: -25

 

Program 1.4 Sort numbers

[2 marks]

Write a C++ program to read four numbers and sorts them in descending order. A sample of the program output looks like this example:

Enter 4 integers

10

230

34

567

567 230 34 10

 


Program 1.5 Decimal to Hexadecimal Conversion                                           [2 marks]


Write a C++ program to get a Decimal number from the user and display the equivalent Hexadecimal value

It is expected that the Hexadecial value is stored in an array of char type.

The user should get an error message for any unrelated data entry at each stage. If the input is not valid, the user is asked to enter new input, until the input is valid.


A couple of samples of the program output may look like the below examples:

 

Enter a Decimal Number: 2046

Equivalent hexadecimal value of 2046 is: 7FE

 

Enter a Decimal Number: AB32

It is not a number! Enter a Decimal number:

2049

Equivalent hexadecimal value of 2049 is: 801