Functions and Recursions – Strings – Problem #6

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

Problem Statement

1. Generate two tables of the form {ID, Card Number, Usage Limit} and {ID, User Name}. i Your program should take the number of entries in the database n from the user and generate the first table and the second table by calling two different functions. In the first table 16-digit card numbers must be randomly generated (First digit of the card numbers should not be zero). Randomly assign a ’Usage Limit’ less than 1000 for each card. Use a one dimensional integer array to store the first table. Card numbers must be distinct. In the second table the names of the users should be provided by the user ( names must be at most 10 character long). Note that ID in both the tables link each user name to their respective Card Number and Usage Limit. Write functions to print those tables and call them from the main(). 2. Write functions to search those tables based on the ID and based on user names. The function should print the result in case the search is successful, otherwise it should print an error message. 3. Write a function to update Usage Limit corresponding to a user name. Print the updated result. If the name is not not valid, print an error message. 4. Write a function using which each user can use their card. The function takes card number and an amount as input, checks whether the card number is valid. If the card is valid then it checks whether the amount is less than or equal to the Usage Limit. If that is the case then the transaction should take place. In the case of a failure, the program should output appropriate error messages like Invalid Card Number, Limit exceeded. Sample Output: Here is one sample output: Please enter n: 3 Table 1: ID 1: Card Number: 9128 8726 0987 2701 Limit: 351 ID 2: Card Number: 5110 0476 6657 6363 Limit: 430 ID 3: Card Number: 9765 7784 2411 8240 Limit: 783 Table 2: ID 1: Name: Ram ID 2: Name: Shyam ID 3: Name: Madhu Enter 1 to Search Enter 2 to Update Enter 3 to Use card Enter 4 to exit Please enter your choice: 1 Enter 1 to search by ID and 2 to search by name Enter your choice: 1 Please enter an ID: 2 ID 2: Name: Shyam Card Number: 5110 0476 6657 6363 Limit: 430 Enter 1 to Search Enter 2 to Update Enter 3 to Use card Enter 4 to exit Please enter your choice: 1 Enter 1 to search by ID and 2 to search by name Enter your choice: 2 Please enter a Name: Ram ID 1: Name: Ram Card Number: 9128 8726 0987 2701 Limit: 351 Enter 1 to Search Enter 2 to Update Enter 3 to Use card Enter 4 to exit Please enter your choice: 2 Please enter the name: Ram Please enter new Limit: 400 Updated Table 1: ID 1: Card Number: 9128 8726 0987 2701 Limit: 400 ID 2: Card Number: 5110 0476 6657 6363 Limit: 430 ID 3: Card Number: 9765 7784 2411 8240 Limit: 783 Enter 1 to Search Enter 2 to Update Enter 3 to Use card Enter 4 to exit Please enter your choice: 3 Enter card number: 9765 7784 2411 8240 Enter amount: 900 Error: The limit is less than the amount entered Enter 1 to Search Enter 2 to Update Enter 3 to Use card Enter 4 to exit Please enter your choice: 4 Goodbye!

Back to Lab Problems
Functions and Recursions/Strings/Problem #6

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #6

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.