0% found this document useful (0 votes)
38 views3 pages

CSC 212 Assignment 1 Overview

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

CSC 212 Assignment 1 Overview

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

Faculty of Natural and Applied Sciences

Computer Science Department

CSC 212 – Spring 2024


Assignment #1

Collaboration Policy:
This assignment must be performed individually

Due Date:
The assignment is due on Sunday 18th February by 11:59 PM. Late Submission will not be accepted.

Deliverables:
Please use Blackboard to submit your assignment. You should submit:
 .cpp file(s) containing your code.

Objective:
The objective of this assignment is to get familiar with C++ programming language and control statements.

Notes:
You are required to use comments to explain what you’re doing.
You must only use the concepts we took in chapters 2 and 4(if , else if and else concepts ONLY).
Problem 1:

In the following problem, you are asked to find the equation of a line, given two points.

The user should enter the coordinates of both points, i.e. x1, y1, x2, y2.
The program should output the equation of the line, in the form “y = mx + b” where m and b are
decimal numbers.

Mathematical background:

Let’s suppose you want to find the equation for a line that passes through the two points: (2,3)
and (4,1).

First of all, the equation of a line is where:

 m is the slope, and


 b is the y-intercept

The slope is always defined as "the change in y over the change in x" or, in equation form:

y 2− y 1
m=
x 2−x 2

So what we need now are the two points that the line passes through. Let's call the first point,
(2,3), point 1, so the x and y numbers given will be called x1 and y1. Or, x1=2 and y1=3.

Also, let's call the second point, (4,1), point 2, so the x and y numbers here will be called x2 and
y2. Or, x2=4 and y2=1.

1−3
Now, just plug the numbers into the formula for m above: m= =−1
4−2

So, we have the first piece to finding the equation of this line, and we can fill it into y = mx + b
like this: y = -x + b

To find b, use any of the two points. For example:


(2,3): y = mx + b or 3 = -1 × 2 + b. Solving for b: b=3-(-1)(2), so b = 5.

The output should be like the following:

The equation of the line that passes through the points (2,3) and (4,1) is y = -x + 5
Note that if m = -1 for example, the “1” in not present in the output.

If x1 = x2, the equation of the line would be: x = x1. And if y1 = y2, the equation would be: y =
y1.

Consider that the user will always enter two distinct points. (No checking needs to be done
whether the two points are the same).

Problem 2:

Write a program that lets the user enter two timings in hours, minutes, seconds, for two people
who are trying to complete a certain task. The program should receive the timing for person 1,
and then for person 2.
The program should output which person finishes first, and the difference between the timings,
in hours, minutes and seconds.

For example if the two timings are:

 Person 1: 2 h 30 min 30 sec


 Person 2: 2 h 50 min 0 sec

The program should display: “Person 1 finishes before, with a difference of 0 h 19 min 30 sec”

Notes:

 No checking needs to be done concerning the values, so suppose the user always enters

positive values, and values for minutes and seconds between 0 and 60.

 If both timings are equal, the program should display a message stating that.

You might also like