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

116 HW2

The document provides instructions for homework assignment #2. It includes 4 problems - the first asks the user to enter a number and determine if it is divisible by 11, the second finds the last prime number before a user-entered number, the third reads temperature data from a file and calculates daily and monthly averages, and the fourth reads bank account and transaction data from files and generates a report with final balances.

Uploaded by

raghadalkhalaf5
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)
25 views3 pages

116 HW2

The document provides instructions for homework assignment #2. It includes 4 problems - the first asks the user to enter a number and determine if it is divisible by 11, the second finds the last prime number before a user-entered number, the third reads temperature data from a file and calculates daily and monthly averages, and the fourth reads bank account and transaction data from files and generates a report with final balances.

Uploaded by

raghadalkhalaf5
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

Homework #2

Due Date: Mar 09 2024


Submission Instructions:

Submit your assignment on the blackboard link, corresponding to your Section:


Please follow the following rules when sending the source code:
1) The name of the file should be q#_myID_section.cpp (for e.g: q1_u000002046_51.cpp)
2) In case two assignments are found to be similar, both students will get ZERO.’
Objectives:

• Basic practice on arithmetic operations.


• Basic practice on control structures (repetition and selection).
• Basic practice on input/output files.

Exercise Out of Mark

1 2
2 3
3 2
4 3

Integrity Statement: Read carefully!


Strict directives have been given to the assistants who will be marking this homework to follow the
University’s policy on cheating. Any student caught cheating in any form will be given zero (0) the first
time. (We will not get into the issue of who copied from whom!!!). If such an act reoccurs, the case will be
sent to the University Student Discipline Committee.
Chapter 5: Loop Structures
Problem1:

Let 𝑛 = 𝑎𝑘 𝑎𝑘−1 𝑎𝑘−2 … 𝑎1 𝑎0 be an integer and 𝑡 = 𝑎0 − 𝑎1 + 𝑎2 − ⋯ + (−1)𝑘 𝑎𝑘 . It is known that 𝒏 is


evenly divisible by 11 if and only if 𝒕 is evenly divisible by 11.
For example, suppose that n = 8784204. Then, t = 4 - 0 + 2 - 4 + 8 - 7 + 8 = 11. Because 11 is divisible by 11,
it follows that 8784204 is divisible by 11.
If n =54063297, then t = 7 - 9 + 2 - 3 + 6 - 0 + 4 - 5 = 2. Because 2 is not divisible by 11, 54063297 is not
divisible by 11.
Write a C++ program that prompts the user to enter a positive integer and then uses this criterion to
determine whether the number is evenly divisible by 11.

1
Input /Output Samples:

Problem 2

Write a C++ program to prompt the user to enter an integer number greater than 1, then find the last
prime number that occurs before the entered number.

Input /Output Sample:

2
Chapter 3: Input/Output
Problem 3 Temperature

Write a C++ program that reads daily temperature data for a Sample output:
month and calculates the average temperature for each day
and the overall temperature of the month. The program should
read the data for the entire month from a file named
temperatures.txt (given). Assume the month has 30 days. The
input file contains one line for each day, where each line has 4
temperature readings (in degrees Celsius) for that day,
separated by spaces. Adjust decimal placed as per the below
sample output.

temeratures.txt content:

Problem 4: Bank Account Report Generator

You are given a text file named accounts.txt containing accounts.txt content:
information about several customers' bank accounts. Each line
in the file represents a single customer's account details with
the following format:
AccountID FirstName LastName InitialBalance
Write a C++ program that reads this file and then performs a
series of operations on each account based on another input transaction.txt content:
file named transactions.txt. This file contains a series of
transactions to be applied to the accounts, formatted as
follows:
AccountID TransactionType Amount
Where TransactionType is either D for deposit or W for
withdrawal. See sample content of transactions.txt file.

After processing all transactions, the program should generate report.txt content:
an output report named report.txt that lists the final balance of
each account, including the account ID, the customer's name,
and the final balance, formatted like the original input. Check
sample output. All input files are given.

You might also like