Lab 06

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Problem 1: Write a C program to manage and evaluate the academic

performance of students. Define a structure Student with the following fields:

 name: A string to store the student's name.


 rollNumber: An integer to store the student's roll number.
 marks: An array of 6 floats to store the marks of the student in 6 subjects. 
totalMarks: A float to store the total marks obtained by the student (calculated).

Task:

1. Create an array of 5 Student structures.


2. Write a function inputStudentData() to input the details (name, roll number, and
marks) for each student.
3. Write a function calculateTotalMarks() that calculates and stores the total marks for
each student based on the marks in the 6 subjects.
4. Write a function displayStudentData() to display the details of all students in a
tabular format, including the total marks and percentage.

N.B. The input-output format is totally up to your creativity.

Source Code:
#include <stdio.h>

struct Student {

char name[50];

int roll;

float marks[6];

float totalMarks;

};

void inputStudentData(struct Student students[], int n) {

for (int i = 0; i < n; i++) {

printf("Enter details for student %d:\n", i + 1);

printf("Name: ");

scanf(" %[^\n]", students[i].name);


printf("Roll Number: ");

scanf("%d", &students[i].roll);

printf("Enter marks for 6 subjects: \n");

for (int j = 0; j < 6; j++) {

printf("Subject %d: ", j + 1);

scanf("%f", &students[i].marks[j]);

printf("\n");

void calculateTotalMarks(struct Student students[], int n) {

for (int i = 0; i < n; i++) {

float sum = 0;

for (int j = 0; j < 6; j++) {

sum += students[i].marks[j];

students[i].totalMarks = sum;

void displayStudentData(struct Student students[], int n) {

printf("\n%-15s %-10s %-15s %-15s\n", "Name", "Roll No", "Total


Marks", "Percentage");

for (int i = 0; i < n; i++) {


float percentage = students[i].totalMarks / 6;

printf("%-15s %-10d %-15.2f %-15.2f\n", students[i].name,


students[i].roll, students[i].totalMarks, percentage);

int main() {

int numStudents = 5;

struct Student students[numStudents];

inputStudentData(students, numStudents);

calculateTotalMarks(students, numStudents);

displayStudentData(students, numStudents);

return 0;

}
Input & Output:
Problem 2: Write a C program to manage the accounts of a bank's customers.
Define a structure Account with the following fields:

 accountNumber: An integer to store the customer's account number.


 accountHolderName: A string to store the customer's name.
 balance: A float to store the current balance in the account.

Task:

1. Create an array of 5 Account structures.


2. Write a function inputAccountData() to input the details (account number, name,
and initial balance) for each account.
3. Write functions deposit() and withdraw() that take an account number as input,
perform the respective transaction, and update the balance.
4. Write a function calculateInterest() that calculates and adds interest to each
account. The interest rate is 5% for accounts with a balance above 50,000, and
3% for accounts with a balance below 50,000.
5. Write a function displayAccountDetails() to display all account details including the
updated balance after interest is added.

N.B. The input-output format is totally up to your creativity.

Source Code:

#include <stdio.h>

#include <string.h>

struct Account {

int accountNumber;

char accountHolderName[100];

float balance;

};

void inputAccountData(struct Account accounts[], int n) {

for (int i = 0; i < n; i++) {

printf("Enter details for account %d:\n", i + 1);

printf("Account Number: ");


scanf("%d", &accounts[i].accountNumber);

printf("Account Holder Name: ");

scanf("%s", accounts[i].accountHolderName);

printf("Initial Balance: ");

scanf("%f", &accounts[i].balance);

printf("\n");

void deposit(struct Account accounts[], int n, int


accountNumber, float amount) {

for (int i = 0; i < n; i++) {

if (accounts[i].accountNumber == accountNumber) {

accounts[i].balance += amount;

printf("Amount %.2f deposited to account number %d.\


n", amount, accountNumber);

return;

printf("Account number %d not found.\n", accountNumber);

void withdraw(struct Account accounts[], int n, int


accountNumber, float amount) {

for (int i = 0; i < n; i++) {

if (accounts[i].accountNumber == accountNumber) {
if (accounts[i].balance >= amount) {

accounts[i].balance -= amount;

printf("Amount %.2f withdrawn from account number


%d.\n", amount, accountNumber);

} else {

printf("Insufficient balance in account number %d.\n",


accountNumber);

return;

printf("Account number %d not found.\n", accountNumber);

void calculateInterest(struct Account accounts[], int n) {

for (int i = 0; i < n; i++) {

if (accounts[i].balance > 50000) {

accounts[i].balance += accounts[i].balance * 0.05;

} else {

accounts[i].balance += accounts[i].balance * 0.03;

printf("\nInterest has been calculated and added to all


accounts.\n");

void displayAccountDetails(struct Account accounts[], int n) {


printf("\nAccount Details After Interest Calculation:\n");

for (int i = 0; i < n; i++) {

printf("Account Number: %d\n",


accounts[i].accountNumber);

printf("Account Holder: %s\n",


accounts[i].accountHolderName);

printf("Current Balance: %.2f\n", accounts[i].balance);

printf("-------------------------\n");

int main() {

int n = 5;

struct Account accounts[n];

inputAccountData(accounts, n);

calculateInterest(accounts, n);

displayAccountDetails(accounts, n);

return 0;

Input & Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy