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

PF Assignment 2

Uploaded by

haniazahra9706
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)
7 views3 pages

PF Assignment 2

Uploaded by

haniazahra9706
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
You are on page 1/ 3

FAST-NUCES

Fall Term 2024

Programming Fundamentals
Assignment 2
Total marks 70

Note: Do not copy code from the internet or any other source, even across the sections. I will
check the plagiarism of the assignment, and it will capture the cheated code from the internet or
copied from class fellows. Those who will try will get some marks for their effort even you do not
get the perfect solution. Copied & Shared work will score a negative grading. Assignment should
be in jupyter. After submission, no excuse will be entertained. No assignment will be accepted
after due
date.

Write C++ code of the following:

1. Last month, Joe purchased some stock in Acme Software, Inc. Here are the details of the
purchase:
marks7
Purchase Details:
● Number of Shares Purchased: 1,000
● Purchase Price per Share: $45.50
Commission Paid on Purchase:
● Joe paid a commission of 2% of the total amount he paid for the stock.
Sale Details:
● Number of Shares Sold: 1,000
● Sale Price per Share: $56.90
Commission Paid on Sale:
● Joe paid another commission, 2% of the total amount he received for the stock.
Objective:
● Calculate Joe's net profit or loss from this investment, considering the purchase and
sale prices and the broker commissions paid during both transactions.

Total Purchase Cost=(Number of Shares×Purchase Price per Share)+Purchase Commission


Purchase Commission=(Number of Shares×Purchase Price per Share)×Commission

Purchase Commission=(Number of Shares×Purchase Price per Share)×Commission Rate

Total Sale Revenue=(Number of Shares×Sale Price per Share)−Sale Commission


Sale Commission=(Number of Shares×Sale Price per Share)×Commission Rate

Net Profit or Loss=Total Sale Revenue−Total Purchase Cost


2. Write a program that calculates the following formula. The current in an alternating current
circuit that contains resistance, capacitance, and inductance in series is given by

Where I = current (amperes), E = voltage (volts), R = resistance (ohms), L = inductance (henrys),


C = capacitance (farads), and f = frequency (hertz). Write a program that reads values for the
voltage, resistance, capacitance, Inductance, and frequency and then calculates and displays the
current. marks:5

3. Write a program to check whether a triangle is valid or not. Valid triangles contain
summation of all angles==180. Get the three angles from the user.
Trick: you will calculate sum of three angles==180 and print valid triangle if sum is 180. Angle1,
angle2 and angle3 should not be zero. marks:3

4. Renting a room at a hotel is, say $100.00 per night. For special occasions, such as a wedding or
conference, the hotel offers a special discount as follows: If the number of rooms booked is at least
10, the discount is 10%; at least 20, the discount is 20%; and at least 30, the discount is 30%. Also
if rooms are booked for at least three days, then there is an additional 5% discount. Write a
program that prompts the user to enter the cost of renting one room, the number of rooms
booked, the number of days the rooms are booked, and the sales tax (as a percent). The
program outputs the cost of renting one room, the discount on each room as a percent, the number
of rooms booked, the number of days the rooms are booked, the total cost of the rooms, the sales
tax, and the total billing amount. Your program must use appropriate named constants to store
special values such as various discounts. Marks 10

5. Collinear points are the points that lie on the same line. If two or more than two points lie on a line
close to or far from each other, then they are said to be collinear. Marks 20
The formula for Collinear points
There are two methods to find the collinear points. They are:
• Slope Formula
• Area of triangle
Using Slope Formula: Three or more points are said to be collinear if the slope of pairs of points is the
same. Suppose, X, Y and Z are the three points, with which we can form three sets of pairs, such that,
XY, YZ and XZ are three pairs of points. Then, as per the slope formula:
If Slope of XY = Slope of YZ = Slope of XZ, then the points X, Y and Z are collinear.
Note: Slope of the line segment joining two points say P1(x1, y1) and P2(x2, y2) is given by the formula:
m = (y2 – y1) / (x2 – x1)
Using the Area of Triangle Formula: If the area of triangle formed by three points is zero, then they
are said to be collinear. It means that if three points are collinear, then they cannot form a triangle.
Suppose, the three points P(x1, y1), Q(x2, y2) and R(x3, y3) are collinear, then by remembering the
formula of area of triangle formed by three points, we get:
(1/2) [x1(y2 – y3) + x2(y3 – y1) + x3(y1 – y2)] = 0

Task 1: Write a C++ program to compute whether the given points are collinear or not by using
slope method.
Task 2: Write a C++ program to compute whether the given points are collinear or not by using
area of triangle method.

6. Sound level L in units of decibel (dB) is determined by: L = 20 log10(p/p0)

where p is the sound pressure of the sound (in Pascals, abbreviated Pa), and p0 is a reference sound
pressure equal to 20 × 10–6 Pa (where L is 0 dB). Marks 20

7. Giving change. Implement a program that directs a cashier how to give change.
The program has two inputs: the amount due and the amount received from the customer.
Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In
order to avoid round off errors, the program user should supply both amounts in pennies, for example
274 instead of 2.74. marks 5
Here's how many of each type of coin you would need to make up one dollar:
● 100 pennies make a dollar.
● 20 nickels make a dollar.
● 10 dimes make a dollar.
● 4 quarters make a dollar.
● 1 dollar coin or bill is already equivalent to a dollar.

GOOD LUCK

You might also like