Programming Fundamentle
Programming Fundamentle
Dear students we will be using auto-grading tools, so failure to submit according to the below format
would result in zero marks in the relevant evaluation instrument.
i. For each question in your assignment, make a separate cpp file e.g. for question 1, make ROLL-
NUM_SECTION_Q#.cpp (23i-0001_A_Q1.cpp) and so on. Each file that you submit must contain
your name, student-id, and assignment # on top of the file in comments.
ii. Combine all your work in one folder. The folder must contain only .cpp files (no binaries, no exe
files etc.).
iii. Run and test your program on a lab machine before submission.
iv. Rename the folder as ROLL-NUM_SECTION (e.g. 23i-0001_A) and compress the folder as a zip file.
(e.g. 23i-0001_A.zip). do not submit .rar file.
v. Submit the .zip file on Google Classroom within the deadline.
vi. Submission other than Google classroom (e.g. email etc.) will not be accepted.
vii. The student is solely responsible to check the final zip files for issues like corrupt file, virus in the
file, mistakenly exe sent. If we cannot download the file from Google classroom due to any reason
it will lead to zero marks in the assignment.
viii. Displayed output should be well mannered and well presented. Use appropriate comment and
indentation in your source code.
ix. Total Marks: 110.
x. If there is a syntax error in code, zero marks will be awarded in that part of assignment.
xi. Your code must be generic.
xii. Solve the assignment by using the concepts of conditional/decision structures as well as the
concepts we have studied before that.
xiii. You cannot use advance constructs like loops / arrays for this assignment
xiv. Try to submit your assignment 3 hours before the deadline to avoid any problem(e.g; Internet
issue etc)
Deadline:
Deadline to submit assignment is 11th October, 2024 11:59 PM. You are supposed to submit your
assignment on GOOGLE CLASSROOM (CLASSROOM TAB not lab). Only “.ZIP” files are acceptable. Other
formats should be directly given ZERO. Correct and timely submission of the assignment is the
responsibility of every student, hence no relaxation will be given to anyone. Late Submission policy will
be applied as described in course outline.
Tip: For timely completion of the assignment, start as early as possible.
Plagiarism: Plagiarism is not allowed. If found plagiarized, you will be awarded zero marks in the
assignment (copying from the internet is the easiest way to get caught ).
Note: Follow the given instruction to the letter, failing to do so will result in a zero.
General Instructions for the assignment:
1. Variable and Function Naming: Use variables and function names that reflect the context of the
problem. Avoid generic names like `x`, `y`, or `z`.
2. Logical Thinking: In your code comments, explain why you chose specific variable names and why
a particular operation (like `+` or `%`) is necessary for the problem’s solution. These comments will
be checked for correctness.
3. Code Structure: Your program should contain a clear `main()` function that primarily calls other
functions where appropriate. Break down your program into smaller functions where necessary.
4. Comments and Documentation: Add a comment at the top of your code that includes your name,
roll number, and a brief description of the program. Each function should have a comment
explaining its purpose and parameters. Use comments to explain any non-obvious parts of your
code.
5. Input/Output Handling: Provide clear instructions when taking input from the user. Format your
output clearly, ensuring it’s easy to understand and follows the requirements of the scenario in
the assignment.
Evaluation Criteria
1. Your assignment will be evaluated based on:
2. Correctness: Does the program produce the correct results for all inputs?
3. Complexity: Are multiple conditions and adjustments applied using appropriate decision
structures (e.g. switch, nested if-else statements and ternary operators etc)?
4. Efficiency: Is the code clean, efficient, and well-commented?
5. Comprehensive Output: Does the program handle all scenarios with clear and concise output?
6. Error Handling: Ensure the program manages invalid inputs gracefully
Question 1: [30 marks]
Interstellar Trading System: Case Study
Background
It’s the year 2150, and interplanetary trade is the lifeblood of the solar system’s economy. The Interstellar
Trading Consortium (ITC) controls all commerce between Earth, Mars, and Jupiter. As the lead software
engineer at ITC, you are tasked with developing an essential part of their trading platform: a program to
decide trade approvals, calculate taxes, and determine bonuses for traders based on various complex
factors.
However, the trading rules have recently been updated to prevent exploitation and make things more
challenging for traders. Your task is to implement these rules in a single C++ program using only
conditional structures (if, else), nested conditions, and some ternary operators for good measure. The
goal is to create a program that processes trade requests and provides accurate decisions based on highly
specific criteria.
The Challenge
Your job is to design and implement a system that processes trade requests for ITC by following these new
rules. The program will need to evaluate multiple factors, ranging from trader experience to trade value,
market volatility, and even interplanetary politics!
Inputs:
For each trade request, your program should take the following inputs:
Rare resources flag: (a boolean indicating if the trade involves rare resources)
Interplanetary trade quota: (percentage value representing how much of their trade quota is used)
Additional Conditions:
1. Age of the trader (integer): Traders above 60 years get an additional 2% tax discount due to seniority
benefits.
2.Planetary trade sanctions: If Earth is under trade sanctions, no trades can originate from Earth
regardless of other conditions.
3.Political alliances: Jupiter traders receive an automatic 5% tax reduction if market volatility is Medium
due to a political agreement between Jupiter and the ITC.
The first task is to determine whether the trader is eligible to conduct the trade.
- Traders from Earth are always eligible unless there are trade sanctions in place.
If any of these conditions are not met, the trade should be denied, and the program should clearly state
the reason for the denial.
Once eligibility is determined, your program must calculate the tax based on a variety of factors. Start
with a base tax rate:
• Earth: 5%
• Mars: 8%
• Jupiter: 12%
• -5% for Jupiter traders if the market volatility is Medium due to political alliances.
• +4% if market volatility is High, regardless of the planet.
Finally, ensure that the tax rate never drops below 0% using a ternary operator. Also, check if the trader
is over 60 years old; if so, subtract another 2% from the final tax as a senior discount.
Bonus amounts
8% of the trade value for Jupiter traders who meet the bonus criteria.
Part 4: Output
Your program should output the following:
• If approved, display:
Flowchart Description:
The flowchart simulates a medical diagnostic and treatment algorithm used by IBM’s Watson computer
system. The process involves diagnosing and treating a patient based on various conditions, using
decisions related to patient status, medical history, symptoms, and environmental factors. The steps
include measuring patient vitals, checking medical conditions, treating the patient based on the diagnosis,
and handling emergencies.
However, the current flowchart uses non-standard symbols and has humorous elements that don’t reflect
professional medical decision-making processes accurately. Your job is to first correct the flowchart, using
proper notation to represent decision points, processes, inputs, and outputs clearly.
Instructions:
1. Step 1: Redraw the Flowchart (hand-drawn):
o Use standard flowchart symbols to represent decision points (diamond),
actions/processes (rectangle), and input/output (parallelogram).
o Correctly represent the flow of logic from the start to the termination points, keeping the
key elements of the original flowchart intact. Ensure all steps are logically connected.
o Remove unnecessary comedic elements and add clarity to each step, using meaningful
labels for processes and decisions (e.g., replacing "surgically adjust patient" with "adjust
patient's posture").
o Submit your new, neatly drawn flowchart using appropriate flowchart notation. (Make
sure you submit a hand drawn flowchart by writing your name and roll number on the
top. You can scan and submit the flowchart alongwith the code file).
2. Step 2: Implement a C++ Program:
o Once the flowchart is redrawn, write a C++ program that follows the logical structure of
the redesigned flowchart.
o The program should simulate the diagnostic steps, allowing users to input patient
conditions (e.g., coughing blood, screaming, pulse rate, etc.) and providing corresponding
treatment steps based on the user’s input.
o Use appriopriate decision structures ( e.g. switch statements , if, if else or nested if-else
etc ) to handle the different decision points.
o For processes like "draw blood" or "measure height and weight," simulate these actions
using simple print statements (e.g., "Drawing blood...").
3. Program Flow:
o The program starts by simulating the initial checks (e.g., is the patient present? Is the
patient screaming?).
o Depending on the user inputs, the program follows through different paths (e.g.,
subduing the patient, applying cream, removing organs) based on the decisions from the
flowchart.
o Use appropriate function calls for each major action (you do not need to implement the
full medical treatment, just simulate it using function calls like applyCream(),
comfortPatient(), etc.).
Patient is screaming.
Oxygen saturation is below 50%. Inject oxygen. Checking blood oxygen saturation...
Discharge patient.
Question 3:[30] - PSL-09 E-Ticketing System (2024) - Rawalpindi Cricket
Stadium
Write a C++ program for a company that is planning to sell e-tickets for the PSL-09 matches being held
at Rawalpindi Cricket Stadium (RCS) in 2024. The program should simulate the ticket-buying process,
including enclosures, pricing, available seats, and discount calculations.
• VIP: Black ones are VIP enclosures with 250 seating capacity each.
• Premium: Red ones are Premium enclosures with 1000 seating capacity each.
• First-class: Yellow and Green ones are first class enclosures with 2000 seating capacity each.
• General: Blue ones are General enclosures with 2500 seating capacity each.
In your code you cannot use Black, Red etc for the enclosures - instead use their appropriate name
for each of the enclosure in your program.
Example Scenario:
• A user selects Match 1 (Islamabad United v Quetta Gladiators, 27 Feb 2024).
• The program displays available enclosures and ticket prices.
• The user selects the Javed Miandad Enclosure (VIP), with 850 seats available.
• The user opts for Family Tickets and enters:
o 3 adults, 2 children.
o CNIC: 12345-6789012-3.
• The program applies the following discounts:
o VIP Enclosure: 10% discount for family bookings.
o 20% discount for children’s tickets.
o Total amount is calculated and displayed.
Question 4:[20]
Part1
Write a program that accepts a date in the format day/month/year (e.g. 29/01/2024) by accepting the
day, month, & year as separate integer inputs. The program should perform the following tasks.
Part2
Write a program that determines whether two triangles are congruent. The program should also
identify and print the type of each triangle (equilateral, isosceles, or scalene) based on its sides.You
are required to perform the following tasks: (By using conditional structures)
1. Input Data: Accept the lengths of all three sides and the measures of all three angles foreach
triangle as inputs.
2. Congruency Check: Determine whether the two triangles are congruent by applying
congruency criteria (SSS, SAS, ASA, AAS, or RHS).
3. Triangle Type Identification: Classify each triangle as equilateral, isosceles, or scalenebased on
its sides.
4. Output Results: Display whether the two triangles are congruent and print the type ofeach
triangle.
Note: Ensure that when checking for congruency, you match the corresponding sides and angles of
both triangles accurately. This means that side 1 of triangle 1 must be compared to thecorresponding
side of triangle 2, and similarly for the angles. Proper alignment of correspondingelements is crucial for
an accurate congruency check.
You can visit this link to understand the concept of congruent triangles:
https://www.onlinemathlearning.com/prove-triangles-congruent.htmls
*** *** HAPPY CODING! *** ***