- 1ProgrammingC/C++Question: 1
A file student.txt contains records in the format: StudentID Name Marks1 Marks2 Marks3 Marks4
Write a program that:
(a)(3 Marks) Calculates total and average marks.
(b) (3 Marks) Assigns grades (A+, A, B,C,F). Where,Marks ≥80 ≥70 ≥60 ≥50 <50 Grade A+ A B C <F
(c) (3 Marks) Displays the top scored three students.
(d) (3 Marks) Displays the subject having the highest average mark.#include #include struct Student { int id; char name[50]; float m1, m2, m3, m4; float total, avg; char grade[3]; }; int main() { FILE *fp; struct Student s[100], temp; int count = 0, i, j; float sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0; fp = fopen("student.txt", "r"); if (fp == NULL) { printf("File not found!\n"); return 1; } while (fscanf(fp, "%d %s %f %f %f %f", &s[count].id, s[count].name, &s[count].m1, &s[count].m2, &s[count].m3, &s[count].m4) != EOF) { s[count].total = s[count].m1 + s[count].m2 + s[count].m3 + s[count].m4; s[count].avg = s[count].total / 4.0; if (s[count].avg >= 80) sprintf(s[count].grade, "A+"); else if (s[count].avg >= 70) sprintf(s[count].grade, "A"); else if (s[count].avg >= 60) sprintf(s[count].grade, "B"); else if (s[count].avg >= 50) sprintf(s[count].grade, "C"); else sprintf(s[count].grade, "F"); sum1 += s[count].m1; sum2 += s[count].m2; sum3 += s[count].m3; sum4 += s[count].m4; count++; } fclose(fp); printf("ID\tName\tTotal\tAverage\tGrade\n"); for(i=0;i<count;i++) { printf("%d\t%s\t%.2f\t%.2f\t%s\n", s[i].id, s[i].name, s[i].total, s[i].avg, s[i].grade); } for(i=0;i<count-1;i++) { for(j=i+1;j s[i].total) { temp = s[i]; s[i] = s[j]; s[j] = temp; } } } printf("\nTop Three Students:\n"); for(i=0;i<3 && i max) { max = avg2; subject = 2; } if(avg3 > max) { max = avg3; subject = 3; } if(avg4 > max) { max = avg4; subject = 4; } printf("\nSubject %d has the highest average (%.2f).\n", subject, max); return 0; }
Code Link
- 2ProgrammingC++Question: 2
Develop a program using object-oriented programming principles.
Requirements
(a) (4 Marks) Create a base class named Employee with the private/protected data members Employee ID, Employee Name, and Basic Salary. In addition, this class should include a constructor to initialize the data members and a method to display employee information.
(b) (5 Marks) Create a derived class named PermanentEmployee that inherits from Employee. It should have methods to calculate a 20% allowance based on the basic salary, to calculate the total salary, and to display the total salary along with the employee information.
(c) (4 Marks) In the main() method:
(i) Create objects for three PermanentEmployee.
(ii) Display the details and total salary of each employee.
(iii) Display the employee with the highest total salary.#include #include using namespace std; class Employee { protected: int employeeID; string employeeName; double basicSalary; public: Employee(int id, string name, double salary) { employeeID = id; employeeName = name; basicSalary = salary; } void displayEmployee() { cout << "Employee ID : " << employeeID << endl; cout << "Employee Name : " << employeeName << endl; cout << "Basic Salary : " << basicSalary << endl; } }; class PermanentEmployee : public Employee { public: PermanentEmployee(int id, string name, double salary) : Employee(id, name, salary) { } double calculateAllowance() { return basicSalary * 0.20; } double calculateTotalSalary() { return basicSalary + calculateAllowance(); } void displayDetails() { displayEmployee(); cout << "Allowance (20%) : " << calculateAllowance() << endl; cout << "Total Salary : " << calculateTotalSalary() << endl; cout << "-----------------------------" << endl; } }; int main() { PermanentEmployee emp1(101, "Rahim", 30000); PermanentEmployee emp2(102, "Karim", 40000); PermanentEmployee emp3(103, "Jamal", 35000); cout < highest->calculateTotalSalary()) highest = &emp2; if (emp3.calculateTotalSalary() > highest->calculateTotalSalary()) highest = &emp3; cout <displayDetails(); return 0; }
View Code
- 3DatabaseQuestion: 3
(15 Marks) A bank introduces a Digital Gold Banking System that allows customers to maintain both conventional bank accounts and digital gold investments. A customer may open one or more accounts, but each account belongs to only one customer and is maintained by a specifie branch. Customers may deposit, withdraw, or transfer money between accounts. Every transaction is processed by an employee and is assigned a iique reference number with its date and time.
Customers can also buy or sell digital gold using money from one of their accounts. Since the market price of gold changes throughout the day, the bank records every price update with its effective timestamp. When a gold transaction occurs, the transaction must permanently store the price that was applicable at that moment, even if the market price changes later. A customer cannot sell more gold than the amount currently owned.
Now, design and implement the database with necessary tables with relevant constraints.Step 1: Identify Main Entities
The system consists of the following entities:
• Customer
• Branch
• Employee
• Account
• BankTransaction (Deposit, Withdrawal, Transfer)
• GoldPriceHistory
• GoldHolding
• GoldTransaction (Buy/Sell)Step 2: Database Tables with Constraints
1. Branch Table
Stores branch information.2. Customer Table
Stores customer details.3. Employee Table
Stores employee information.4. Account Table
Stores bank account information.Constraint:
Each account belongs to only one customer and one branch.5. BankTransaction Table
Stores Deposit, Withdrawal, and Transfer transactions.Constraint:
Every transaction has a unique reference number and is processed by one employee.6. GoldPriceHistory Table
Stores every gold price update with its effective timestamp.Constraint:
Each price update is recorded with its effective date and time.7. GoldHolding Table
Stores the total amount of gold owned by each customer.8. GoldTransaction Table
Stores Buy and Sell transactions of digital gold.Important Constraint:
The AppliedPrice must be stored permanently at the time of the transaction. Future changes in the market price must not affect previous transactions.Step 3: Business Rules Enforcement
Key Constraints:
• Account balance cannot be negative.
• Transfer requires both FromAccount and ToAccount.
• Deposit uses only ToAccount.
• Withdrawal uses only FromAccount.
• Gold price must be positive.
• Gold quantity (grams) must be positive.
• A customer cannot sell more gold than the amount currently owned.The last rule is enforced using a BEFORE INSERT Trigger on the GoldTransaction table.
Step 4: Trigger for Preventing Excess Gold Sale
A BEFORE INSERT Trigger checks the customer's current gold balance before a Sell transaction. If the customer attempts to sell more gold than available, the transaction is rejected.
Step 5: Relationship Summary
Entity Relationship Customer 1 : M Account Branch 1 : M Account Branch 1 : M Employee Employee 1 : M BankTransaction Customer 1 : 1 GoldHolding Customer 1 : M GoldTransaction Account 1 : M GoldTransaction Step 6: Conclusion
The proposed database design satisfies all the requirements of the Digital Gold Banking System.
• Supports multiple accounts for each customer.
• Maintains branch-wise account ownership.
• Records all banking transactions with unique reference numbers.
• Stores historical gold prices with timestamps.
• Preserves the applied gold price permanently for every gold transaction.
• Prevents customers from selling more gold than they own.
• Ensures data integrity using Primary Keys, Foreign Keys, CHECK Constraints, and Triggers.
Real Question Photo


