0% found this document useful (0 votes)
1 views2 pages

Homeworks 2

Uploaded by

slayerslay45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Homeworks 2

Uploaded by

slayerslay45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MKT1142 - Homework 1: Variables, Memory & Physical Mathematics

Objective: Practice declaring variables, choosing the correct data types for physical hardware
limits, and performing mathematical operations without losing precision due to compiler
behavior.

Instructions: Write a separate C++ program for each question. Ensure your variables are named
clearly using camelCase(e.g., sensorVoltage, not x).

Question 1: The ADC Sensor Calibrator (Difficulty: Medium-Easy)

Scenario: You are programming a microcontroller (like an Arduino) to read an analog


temperature sensor. Microcontrollers cannot read "temperature" directly; they read voltage and
convert it into a digital integer using an Analog-to-Digital Converter (ADC).

Your ADC has a 10-bit resolution, meaning it reads a voltage from 0.0V to 5.0V and outputs an
integer between 0 and 1023. The specific temperature sensor you are using increases its output
by 0.01V for every 1°C.

Your Task: Write a C++ program that:

1. Prompts the user to enter a raw ADC integer value (from 0 to 1023).
2. Calculates the physical voltage (Voltage = (ADC Value / 1023) * 5.0).
3. Calculates the actual temperature in Celsius (Temperature = Voltage / 0.01).
4. Prints the final Voltage and Temperature to the console with descriptive text.

Hint: Be very careful with integer division. If you divide an int by an int, the compiler will
truncate the decimal!

Question 2: The Robotic Arm Payload Calculator (Difficulty: Medium-Hard)

Scenario: An industrial robotic arm is designed to pick up solid cylindrical steel payloads. The
safety system needs to know the exact gravitational force (in Newtons) acting on the payload
before attempting to lift it. If the force calculation is wrong, the motors will burn out.

Your Task: Write a C++ program that:


1. Prompts the user to input the radius (in cm) and height (in cm) of the steel cylinder.
2. Uses a constant (const float PI = 3.14159;) to calculate the volume.
3. Calculates the mass in grams, then converts it to kilograms.
4. Calculates the downward force in Newtons.
5. Prints the calculated Volume, Mass (in kg), and Force (in N) to the screen.

Question 3: The CNC Micro-Stepping Trap (Difficulty: Very Hard)

Scenario: You are writing the movement algorithm for a high-precision CNC milling machine.
The machine's cutting tool is moved by a stepper motor connected to a lead screw.

The Hardware Specs:

• The motor takes exactly 200 steps to complete one full revolution.
• The motor is attached to a gearbox with a 1:25.4 reduction ratio (the motor must turn
25.4 times for the output shaft to turn once).
• The output shaft is connected to a lead screw that moves the cutting tool exactly 5.0
millimeters for every 1 full revolution of the shaft.

Your Task: Write a C++ program that asks the user to input a desired travel distance in
millimeters (e.g., 150.5). The program must calculate and print the exact, total number of
electrical pulses (steps) the microcontroller must send to the motor to travel that distance.

The Engineering Trap (Read Carefully):

1. Your final answer for "total steps" cannot be a decimal. You cannot send "half a pulse" to
a motor. It must be a whole number.
2. Think very carefully about the Data Type you use to store the "total steps." If the user
requests a movement of 3000 mm (3 meters), a standard 16-bit integer (short int) will
overflow, crash the system, and destroy the machine. You must use a data type large
enough to hold millions of steps safely.

You might also like