Sample
Sample
Matrices are fundamental mathematical structures used to organize and manipulate data in
various fields including mathematics, computer science, and engineering. In mathematics,
a matrix is a rectangular array of numbers (or elements) arranged in rows and columns.
Each element in a matrix is uniquely identified by its row and column indices. Matrices
are particularly useful for representing and solving systems of linear equations,
performing transformations in geometry, and storing and processing multidimensional
data in computer algorithms. In C++, matrices can be represented using arrays. Here you
are required to write a C++ program to perform two different operations on a square
matrix of size n*n using c++ functions.
a. Transpose: A function used for transposing elements of a matrix.
b. Upper Triangle Sum: A function to calculate and print the sum of elements
in the upper triangle (including the diagonal) of the matrix.
c. Lower triangle sum: A function to calculate and print the sum of elements in
the lower triangle (excluding the diagonal) of the matrix.
Requirements:
Prompt the user to enter the size n*n of the matrix.
Allow the user to enter the elements of the matrix.
Implement functions/methods to perform each operation.
Display the original matrix, its transpose, and the sum of the upper and lower triangle
elements.
2. The Number Guessing Game is a classic interactive program where the computer
randomly selects a number within a specified range, typically between 1 and 100. The
player's objective is to guess this number within a limited number of attempts, usually
around 10. After each guess, the program provides feedback to the player, indicating
whether the guessed number is higher, lower, or correct. The game continues until the
player guesses the correct number or exhausts all 10 attempts. It challenges players to
apply logical deduction and strategic guessing while providing immediate feedback,
making it a popular choice for demonstrating basic programming concepts like loops,
conditional statements, and random number generation in C++. If the user successfully
guesses the number, he may be asked if he/she wants to play further or just quit the game.
Design a C++ program for a number guessing game where the computer randomly selects
a number between 1 and 100, and the user tries to guess it. The program should include:
a. Random Number Generation: Generate a random number between 1 and
100.
b. User Input: Prompt the user to guess the number and provide feedback
(higher, lower, or correct).
c. Attempts Limit: Limit the number of attempts (e.g., 10 attempts).
d. Game Result: Display whether the user guessed the number correctly or ran
out of attempts.
e. Continue/Quit: Display whether the user guessed the number correctly or ran
out of attempts.
Detailed Requirements:
Use loops for iterating through attempts and conditional statements for checking the
guess.
Implement random number generation using standard C++ libraries.
Provide feedback to the user based on their guesses and ensure clear instructions and
outputs.
General Guidelines:
Modularity: You are encouraged to use functions or methods to encapsulate logic for
different functionalities.
Structured Programming: Emphasize the use of structures, loops, functions, and
conditional statements to achieve program goals.
Documentation and Comments: You are advised to document your code effectively,
explaining the purpose of functions, variables, and any complex logic.
3. The ATM Simulation problem involves creating a program that mimics the functionalities
of an Automated Teller Machine (ATM). The program allows users to interact with their
bank account through a console interface. Users can perform operations such as checking
their account balance, depositing funds into their account, withdrawing money (provided
there are sufficient funds), and viewing a history of their recent transactions. The
simulation requires implementing a structure, to represent an account with attributes like
account number, current balance, and transaction history. Functions or methods are
defined to handle each operation, ensuring proper validation of user inputs and adequate
error handling for scenarios such as insufficient funds or incorrect user actions. Key
features include maintaining transaction records, updating balances accurately after each
transaction, and providing clear feedback to users through the console interface. This
problem not only tests students' understanding of basic C++ programming concepts like
structures, functions, loops, and conditional statements but also challenges them to design
and implement a user-friendly banking system simulation with realistic transactional
behaviour. Implementation of the ATM Simulation involves integrating control structures
like loops and conditional statements to manage the flow of operations and ensure the
program responds appropriately to user commands. Error handling mechanisms are
crucial to manage edge cases, including invalid inputs, insufficient funds for withdrawals,
and ensuring data integrity throughout each transaction. Furthermore, the program should
provide clear and concise feedback to users at every stage, confirming successful
transactions or alerting them to errors with informative messages. Create a C++ program
to simulate a similar ATM machine. The program should offer the following operations:
1. Balance Inquiry: Display the current balance of the account using account no.
2. Deposit: Allow user to deposit an amount into an account.
3. Withdrawal: Allow the user to withdraw an amount from an account (ensure
sufficient balance).
4. Transaction History: Display the last 5 transactions (including deposits,
withdrawals, and balance inquiries).
Detailed Requirements:
Use a structure or class to represent the account with attributes such as account
number, balance, and transaction history.
Implement functions/methods for each operation mentioned above.
Use loops and conditional statements to manage user interactions and validate inputs.
Ensure proper handling of edge cases, such as insufficient balance for withdrawals
and invalid inputs.