0% found this document useful (0 votes)
108 views37 pages

Xii Objectives

The document outlines a series of programming tasks in C language and database creation tasks in MS Access, covering various topics such as data input, calculations, and database management. Each task includes specific requirements for both programming and database design, including creating tables, inputting records, and performing queries. The document serves as a comprehensive guide for students to practice their programming and database skills.

Uploaded by

anipak.1234
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)
108 views37 pages

Xii Objectives

The document outlines a series of programming tasks in C language and database creation tasks in MS Access, covering various topics such as data input, calculations, and database management. Each task includes specific requirements for both programming and database design, including creating tables, inputting records, and performing queries. The document serves as a comprehensive guide for students to practice their programming and database skills.

Uploaded by

anipak.1234
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/ 37

1

Option I (C_Language & MS Access)

1(a) C_language :Write a Program that reads and Print the data using escape sequence
(Asking the name, age, height and Gender of Student) using printf and scanf Statements
.
1(b)MS Access: Create a Database of Library (Book _Id, Name, Status )
i. Create a suitable primary key , input 20 records with different
names
ii. Display a list of Book which are issued .
iii. Find the list of available Books.

2(a) C_language : Write a program that read marks of five subject ,calculate the
total marks , percentage and state whether candidate is pass or fail.

2(b)MS Access: Create a Database in MS-Access of Bank Accounts


Create two tables , Create relationship between tables .
i. Required fields of 1st table are ,
Acc_ID , Acc_Name, Acc_Address, Acc_Phone ,Acc_Email ii.
Required field of 2nd table are :
Acc_ID , Acc_status iii. Search the desired Acc_ID ,
Delete the Desired Acc_ID.

3(a) C_language : Find the factorial of an inputted number.

3(b) MS Access: Create a Database in MS-Access of Students Attendance.


Create two tables , Create relationship Between tables .
i. Required fields of 1st table are:
St_Id. St_Name , St_address,St_Phone, St_Email.
ii. Required fields of 2 nd table are :
St_Id , St_Attendence. iii. Search the desired St_Id ,
Delete the desired St_Id also Update desired St_Id.
2

4(a) C_language :Write a program to generate the table of any inputted number.
4(b) MS Access: Create a Hospital record Database in MS_Access.
i. Create following tables , input 5 records
ii. Create patient_id as a Primary Key . iii. Create relationship
between tables . iv. Search all patient under treatment of a
particular Doctor name “Dr. Muhammad Faizan”
v. Update the prescription of particular patient.

Patient
Patient_Id Name Address Doctor Admit Discharge Discharge Charges
Name date Status Date

Status
Patient_Id Date Doctor Test report Prescription Disease
Name

5(a) C_language : Write a program that finds out the greatest number among three
input numbers.
5(b) MS Access: Create a Hospital record Database in MS_Access.
i. Create following tables , input 5 records
ii. Create patient_id as a Primary Key . iii. Create relationship
between tables . iv. Search all patient under treatment of a
particular Doctor name “Dr. Muhammad Faizan”
v. Update the prescription of particular patient.

Patient
Patient_Id Name Address Doctor Admit Discharge Discharge Charges
Name date Status Date

Status
Patient_Id Date Doctor Test report Prescription Disease
Name
3

6(a) C_language : Write a program which uses arithmetic operators to calculate


the area of triangle and volume of sphere .
6(b) MS Access: Create a Database of Library (Book _Id, Name, Status )
i. Create a suitable primary key , input 20 records with
different names
ii. Display a list of Book which are issued .
iii. Find the list of available Books.

7(a) C_language : Write a program ,that convert upper case letter to lower case
letter and vise versa (using function ) .
7(b) MS Access: Create a Database in MS-Access of Students Attendance.
Create two tables , Create relationship Between tables .
i. Required fields of 1st table are: St_Id. St_Name ,
St_address,St_Phone, St_Email.
ii. Required fields of 2 nd table are St_Id , St_Attendence.
Search the desired St_Id , iii. Delete the desired St_Id
also Update desired St_Id.

8(a) C_language : Write a program to draw a check-board using if-else statement


and nested for loops.
8(b) MS Access: Create a Database in MS-Access of Bank Accounts Create
two tables , Create relationship between tables .
i. Required fields of 1st table are ,
1. Acc_ID , Acc_Name, Acc_Address, Acc_Phone
,Acc_Email
ii. Required field of 2nd table are :
1. Acc_ID , Acc_status iii. Search the desired Acc_ID
, Delete the Desired Acc_ID.

9(a) C_language :Write a program that generate characters corresponding to ASCII


codes from 32 to 127 (using any loop).

9(b) MS Access: Create a Database in MS-Access of Students Attendance. Create


two tables , Create relationship Between tables .
i. Required fields of 1st table are: St_Id. St_Name ,
St_address,St_Phone, St_Email. ii. Required fields of 2 nd
table are : St_Id , St_Attendence. iii. Search the desired
St_Id ,
iv. Delete the desired St_Id also Update desired St_Id.
4

10(a) C_language : Write a program that reads and prints the data using escape
sequence (asking the name, age ,height and gender of student using scanf() and
printf() statements).
10(b) MS Access: Create a Database of students result information(St_Id, St_name ,
St_Marks)
i. Create a primary key as a St_Id.
ii. Input 10 records .
iii. Sort all records on descending order on St_marks.
iv. Display all records.

11(a) C_language : Write a program that input a number and then check it whether it
is prime or not .
11(b) MS Access: Create a Database of Library (Book _Id, Name, Status )
i. Create a suitable primary key , input 20 records with different
names
ii. Display a list of Book which are issued .
iii. Find the list of available Books.

12(a) C_language : Write a program, to Print Square and cube of first ten even
numbers.

12(b) MS Access: Create a Database in MS-Access of Bank Accounts

Create two tables , Create relationship between tables .


i. Required fields of 1st table are , Acc_ID , Acc_Name, Acc_Address,
Acc_Phone ,Acc_Email ii. Required field of 2nd table
are Acc_ID , Acc_status
iii. Search the desired Acc_ID , Delete the Desired Acc_ID.

13(a) C_language : Write a program ,which uses Switch and break statement .
13(b) MS Access: Create a Database of student information (St_Id, St_Name ,
Class, Group, Sex)
i. Create St_Id as a Primary key.
ii. Input 20 records . iii. Find the list of female pre-engineering
group.
iv. Find the list of male Pre-engineering group.
5

14(a) C_language : Write a program using nested for loop to print the following
output .

1
12
123
1234
12345

14(b) MS Access: Create a Database of student information (St_Id, St_Name ,


Class, Group, Sex)
i. Create St_Id as a Primary key.
ii. Input 20 records . iii. Find the list of female pre-engineering
group.
iv. Find the list of male Pre-engineering group.

15(a) C_language : Write a program that input any two number and then pass these
numbers as arguments a function sum1 and then print their sum.
15(b) MS Access: Create a Database of students result information(St_Id, St_name ,
St_Marks)
i. Create a primary key as a St_Id.
ii. Input 10 records .
iii. Sort all records on descending order on St_marks.
iv. Display all records.

16(a) C_language : Write a program to calculate a pay roll of employees. Read the
basic pay from key board. Calculate medical allowance as 15% of basic pay,
conveyance allowance as 20% and house rent 45% of basic pay and deduction of GP
fund 7% of pay. Calculate gross pay and net pay.
16(b) MS Access: Create a Database of Library (Book _Id, Name, Status )
iv. Create a suitable primary key , input 20 records with
different names
v. Display a list of Book which are issued .
vi. Find the list of available Books.
1(a) C Program
#include <stdio.h>

int main() {
char name[50];
int age;
float height;
char gender;

printf("Enter your name: ");


scanf("%s", name);

printf("Enter your age: ");


scanf("%d", &age);

printf("Enter your height in centimeters: ");


scanf("%f", &height);

printf("Enter your gender (M/F): ");


scanf(" %c", &gender);

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


printf("Name: %s\n", name);
printf("Age: %d\n", age);
printf("Height: %.2f cm\n", height);
printf("Gender: %c\n", gender);

return 0;
}

Explanation:
● #include <stdio.h>: This line includes the standard input/output library, which provides
functions like printf and scanf.
● int main() { ... }: This is the main function where the program execution begins.
● Variables: We declare variables to store the student's name (name), age (age), height
(height), and gender (gender).
● printf: This function is used to display output on the screen. Escape sequences like \n
(new line) are used to format the output.
● scanf: This function reads input from the user. The %s, %d, %f, and %c are format
specifiers that tell scanf what type of data to expect (string, integer, float, and character
respectively).
● %.2f: This format specifier in the printf statement is used to print the height with two
decimal places.
1(b) MS Access Database
i. Create the Database
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and give it a name like "LibraryDB".
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Book_ID: (Number, Long Integer, set as Primary Key)
■ Name: (Short Text)
■ Status: (Short Text) - This field will store "Issued" or "Available".
4. Save the Table: Save the table as "Books".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Books" table.
2. Enter Data: Enter 20 records with different book names. Make sure to assign a unique
Book_ID to each book and set the Status as "Issued" or "Available" accordingly.
iii. Queries
● Display Issued Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Issued" in the Criteria row.
5. Run the Query: Click "Run" to see the list of issued books.
● Display Available Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Available" in the Criteria row.
5. Run the Query: Click "Run" to see the list of available books.
Important Notes:
● Primary Key: The Book_ID is set as the primary key to ensure that each book has a
unique identifier.
● Data Types: Choose appropriate data types for your fields (e.g., Number for Book_ID,
Short Text for Name and Status).
● Queries: Queries allow you to easily filter and retrieve specific data from your database.
2(a) C Program for Calculating Marks
#include <stdio.h>

int main() {
int sub1, sub2, sub3, sub4, sub5;
int total;
float percentage;

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


scanf("%d%d%d%d%d", &sub1, &sub2, &sub3, &sub4, &sub5);

total = sub1 + sub2 + sub3 + sub4 + sub5;


percentage = (float)total / 500 * 100;

printf("Total Marks: %d\n", total);


printf("Percentage: %.2f%%\n", percentage);

if (percentage >= 40) { // Assuming 40% is the passing percentage


printf("Result: Pass\n");
} else {
printf("Result: Fail\n");
}

return 0;
}

Explanation:
● Input: The program takes marks for five subjects as input from the user.
● Calculation: It calculates the total marks and percentage based on the input.
● Pass/Fail: It checks if the percentage is greater than or equal to 40% (you can change
this passing threshold). Based on the condition, it prints "Pass" or "Fail".
● %.2f%%: This format specifier in the printf statement prints the percentage with two
decimal places and adds a '%' sign.
2(b) MS Access Database for Bank Accounts
i. Create Tables
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "BankDB").
3. Create the First Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "AccountInfo" table:
■ Acc_ID: (Number, Long Integer, set as Primary Key)
■ Acc_Name: (Short Text)
■ Acc_Address: (Short Text)
■ Acc_Phone: (Short Text)
■ Acc_Email: (Short Text)
4. Create the Second Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "AccountStatus" table:
■ Acc_ID: (Number, Long Integer, set as Primary Key)
■ Acc_Status: (Short Text) - (e.g., "Active", "Inactive", "Closed")
ii. Create Relationship
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add both "AccountInfo" and "AccountStatus" tables to the Relationships
window.
4. Create Relationship:
○ Drag the Acc_ID field from the "AccountInfo" table to the Acc_ID field in the
"AccountStatus" table.
○ In the "Edit Relationships" dialog box, ensure "Enforce Referential Integrity" is
checked. Click "Create". This creates a one-to-one relationship between the tables.
iii. Search and Delete Records
● Search for Acc_ID:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "AccountInfo" table to the query.
3. Select Fields: Add the fields you want to see in the results (e.g., Acc_ID,
Acc_Name).
4. Add Criteria: In the Acc_ID column, enter the ID you want to search for in the
Criteria row.
5. Run the Query: Click "Run" to see the matching record.
● Delete an Account:
1. Open the Table: Open the "AccountInfo" table in Datasheet View.
2. Find the Record: Locate the record with the Acc_ID you want to delete.
3. Delete: Select the record and press the Delete key. (Since you have referential
integrity, deleting from "AccountInfo" will also delete the corresponding record in
"AccountStatus").
Important Notes:
● Referential Integrity: Enforcing referential integrity helps maintain data consistency by
preventing accidental deletion of related records.
● Deleting Records: Be cautious when deleting records, as the action cannot be easily
undone.
3(a) C Program to Find Factorial
#include <stdio.h>

int main() {
int num, i;
unsigned long long factorial = 1; // Use a larger data type for
factorials

printf("Enter a non-negative integer: ");


scanf("%d", &num);

if (num < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
for (i = 1; i <= num; ++i) {
factorial *= i;
}
printf("Factorial of %d = %llu\n", num, factorial);
}

return 0;
}

Explanation:
● Input: The program takes a non-negative integer as input.
● Factorial Calculation: It uses a for loop to calculate the factorial. The loop iterates from 1
to the input number, multiplying each number with the factorial variable.
● Output: The program prints the calculated factorial.
● unsigned long long: This data type is used to store larger factorials as they can grow
very quickly.
3(b) MS Access Database for Student Attendance
i. Create Tables
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "AttendanceDB").
3. Create the First Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "StudentInfo" table:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ St_Address: (Short Text)
■ St_Phone: (Short Text)
■ St_Email: (Short Text)
4. Create the Second Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "Attendance" table:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Attendance: (Short Text) - (e.g., "Present", "Absent", "Late")
ii. Create Relationship
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add both "StudentInfo" and "Attendance" tables to the Relationships
window.
4. Create Relationship:
○ Drag the St_ID field from the "StudentInfo" table to the St_ID field in the
"Attendance" table.
○ In the "Edit Relationships" dialog box, ensure "Enforce Referential Integrity" is
checked. Click "Create". This creates a one-to-one relationship between the tables.
iii. Search, Delete, and Update Records
● Search for St_ID:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "StudentInfo" table to the query.
3. Select Fields: Add the fields you want to display (e.g., St_ID, St_Name).
4. Add Criteria: In the St_ID column, enter the ID you want to search for in the
Criteria row.
5. Run the Query: Click "Run" to see the matching record.
● Delete a Student Record:
1. Open the Table: Open the "StudentInfo" table in Datasheet View.
2. Find the Record: Locate the record with the St_ID you want to delete.
3. Delete: Select the record and press the Delete key. (Referential integrity will delete
the related record in the "Attendance" table.)
● Update a Student Record:
1. Open the Table: Open the "StudentInfo" table in Datasheet View.
2. Find the Record: Locate the record with the St_ID you want to update.
3. Edit: Double-click the field you want to change and enter the new value.
Important Notes:
● Referential Integrity: Ensures data consistency by preventing accidental deletion or
modification of related data.
● Data Validation: You can add validation rules to the St_Attendance field to ensure only
valid values (e.g., "Present", "Absent", "Late") are entered.
● Forms: For a more user-friendly way to update and enter data, you can create forms in
Access.
● https://github.com/Pradeep0117/datastructure
● https://github.com/5Somasekhar/Data-Structures
4(a) C Program to Generate a Multiplication Table
#include <stdio.h>

int main() {
int num, i;

printf("Enter an integer: ");


scanf("%d", &num);

printf("Multiplication table of %d:\n", num);


for (i = 1; i <= 10; ++i) {
printf("%d x %d = %d\n", num, i, num * i);
}

return 0;
}

Explanation:
● Input: The program takes an integer as input from the user.
● Loop: It uses a for loop to iterate from 1 to 10.
● Calculation and Output: Inside the loop, it calculates the product of the input number
and the current loop counter (i) and prints the result in the format "num x i = product".
4(b) MS Access Database for Hospital Records
i. Create Tables and Input Records
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "HospitalDB").
3. Create the "Patients" Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Patient_ID: (Number, Long Integer, set as Primary Key)
■ Patient_Name: (Short Text)
■ Address: (Short Text)
■ Phone: (Short Text)
■ Doctor_ID: (Number, Long Integer) - This will link to the Doctors table.
4. Create the "Doctors" Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Doctor_ID: (Number, Long Integer, set as Primary Key)
■ Doctor_Name: (Short Text)
■ Specialization: (Short Text)
5. Create the "Treatments" Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Treatment_ID: (Number, Long Integer, set as Primary Key)
■ Patient_ID: (Number, Long Integer) - This will link to the Patients table.
■ Doctor_ID: (Number, Long Integer) - This will link to the Doctors table.
■ Diagnosis: (Short Text)
■ Prescription: (Short Text)
6. Input Records: Enter 5 sample records into each table, making sure to use consistent
Doctor_ID and Patient_ID values across the tables.
ii. Create Relationships
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add "Patients", "Doctors", and "Treatments" tables to the Relationships
window.
4. Create Relationships:
○ Drag Doctor_ID from "Doctors" to Doctor_ID in "Patients" (one-to-many
relationship).
○ Drag Patient_ID from "Patients" to Patient_ID in "Treatments" (one-to-many
relationship).
○ Drag Doctor_ID from "Doctors" to Doctor_ID in "Treatments" (one-to-many
relationship).
○ Ensure "Enforce Referential Integrity" is checked for all relationships.
iii. Search for Patients under "Dr. Muhammad Faizan"
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Tables: Add "Patients", "Doctors", and "Treatments" tables to the query.
3. Select Fields: Add Patient_Name from the "Patients" table.
4. Join Tables: Make sure the tables are joined correctly based on the relationships you
created.
5. Add Criteria: In the Doctor_Name column of the "Doctors" table, type "Dr. Muhammad
Faizan" in the Criteria row.
6. Run the Query: Click "Run" to see the list of patients.
iv. Update Prescription
1. Open the Table: Open the "Treatments" table in Datasheet View.
2. Find the Record: Locate the treatment record for the patient you want to update.
3. Edit: Double-click the Prescription field and enter the new prescription.
Important Notes:
● Data Types: Choose appropriate data types for your fields.
● Referential Integrity: Crucial for maintaining data consistency.
● Forms: Create user-friendly forms for data entry and viewing.
● Reports: Generate reports to summarize and analyze data.
● Normalization: Consider further normalization of the database if needed (e.g., separate
tables for medications, diagnoses, etc.).
● https://www.iswori.com.np/2023/03/important-c-programming-questions-class-12-compute
r-science-neb-board.html
5(a) C Program to Find the Greatest Number
#include <stdio.h>

int main() {
int num1, num2, num3;

printf("Enter three numbers: ");


scanf("%d %d %d", &num1, &num2, &num3);

if (num1 >= num2 && num1 >= num3) {


printf("%d is the greatest number.\n", num1);
} else if (num2 >= num1 && num2 >= num3) {
printf("%d is the greatest number.\n", num2);
} else {
printf("%d is the greatest number.\n", num3);
}

return 0;
}

Explanation:
● Input: The program takes three integers as input.
● Comparison: It uses if-else if-else statements to compare the numbers.
○ The first if checks if num1 is greater than or equal to both num2 and num3.
○ The else if checks if num2 is greater than or equal to both num1 and num3.
○ The else block executes if neither of the above conditions is true, meaning num3 is
the greatest.
● Output: The program prints the greatest number.
5(b) MS Access Database for Hospital Records
This is the same as the previous question (4(b)). Here's the solution again for your convenience:
i. Create Tables and Input Records
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "HospitalDB").
3. Create the "Patients" Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Patient_ID: (Number, Long Integer, set as Primary Key)
■ Patient_Name: (Short Text)
■ Address: (Short Text)
■ Phone: (Short Text)
■ Doctor_ID: (Number, Long Integer) - This will link to the Doctors table.
4. Create the "Doctors" Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Doctor_ID: (Number, Long Integer, set as Primary Key)
■ Doctor_Name: (Short Text)
■ Specialization: (Short Text)
5. Create the "Treatments" Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Treatment_ID: (Number, Long Integer, set as Primary Key)
■ Patient_ID: (Number, Long Integer) - This will link to the Patients table.
■ Doctor_ID: (Number, Long Integer) - This will link to the Doctors table.
■ Diagnosis: (Short Text)
■ Prescription: (Short Text)
6. Input Records: Enter 5 sample records into each table, making sure to use consistent
Doctor_ID and Patient_ID values across the tables.
ii. Create Relationships
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add "Patients", "Doctors", and "Treatments" tables to the Relationships
window.
4. Create Relationships:
○ Drag Doctor_ID from "Doctors" to Doctor_ID in "Patients" (one-to-many
relationship).
○ Drag Patient_ID from "Patients" to Patient_ID in "Treatments" (one-to-many
relationship).
○ Drag Doctor_ID from "Doctors" to Doctor_ID in "Treatments" (one-to-many
relationship).
○ Ensure "Enforce Referential Integrity" is checked for all relationships.
iii. Search for Patients under "Dr. Muhammad Faizan"
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Tables: Add "Patients", "Doctors", and "Treatments" tables to the query.
3. Select Fields: Add Patient_Name from the "Patients" table.
4. Join Tables: Make sure the tables are joined correctly based on the relationships you
created.
5. Add Criteria: In the Doctor_Name column of the "Doctors" table, type "Dr. Muhammad
Faizan" in the Criteria row.
6. Run the Query: Click "Run" to see the list of patients.
iv. Update Prescription
1. Open the Table: Open the "Treatments" table in Datasheet View.
2. Find the Record: Locate the treatment record for the patient you want to update.
3. Edit: Double-click the Prescription field and enter the new prescription.
Important Notes:
● Data Types: Choose appropriate data types for your fields.
● Referential Integrity: Crucial for maintaining data consistency.
● Forms: Create user-friendly forms for data entry and viewing.
● Reports: Generate reports to summarize and analyze data.
● Normalization: Consider further normalization of the database if needed (e.g., separate
tables for medications, diagnoses, etc.).
● http://www.cprogrammingnotes.com/question/largest-three-numbers.html
● https://github.com/Naoltolesa/programming-1
6(a) C Program to Calculate Area and Volume
#include <stdio.h>
#include <math.h> // Include math.h for the pow() function

int main() {
float base, height, radius;
float area, volume;

// Calculate the area of a triangle


printf("Enter base and height of the triangle: ");
scanf("%f %f", &base, &height);
area = 0.5 * base * height;
printf("Area of the triangle = %.2f\n", area);

// Calculate the volume of a sphere


printf("Enter radius of the sphere: ");
scanf("%f", &radius);
volume = (4.0 / 3.0) * 3.14159 * pow(radius, 3);
printf("Volume of the sphere = %.2f\n", volume);

return 0;
}

Explanation:
● #include <math.h>: This line includes the math library, which provides mathematical
functions like pow() for calculating the power of a number.
● Input: The program takes the base and height of a triangle and the radius of a sphere as
input.
● Area Calculation: The area of the triangle is calculated using the formula 0.5 * base *
height.
● Volume Calculation: The volume of the sphere is calculated using the formula (4.0 / 3.0)
* pi * radius^3 (where pi is approximated as 3.14159).
● Output: The program prints the calculated area and volume.
6(b) MS Access Database for Library
This is the same as question 1(b). Here's the solution again:
i. Create the Database
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and give it a name like "LibraryDB".
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Book_ID: (Number, Long Integer, set as Primary Key)
■ Name: (Short Text)
■ Status: (Short Text) - This field will store "Issued" or "Available".
4. Save the Table: Save the table as "Books".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Books" table.
2. Enter Data: Enter 20 records with different book names. Make sure to assign a unique
Book_ID to each book and set the Status as "Issued" or "Available" accordingly.
iii. Queries
● Display Issued Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Issued" in the Criteria row.
5. Run the Query: Click "Run" to see the list of issued books.
● Display Available Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Available" in the Criteria row.
5. Run the Query: Click "Run" to see the list of available books.
Important Notes:
● Primary Key: The Book_ID is set as the primary key to ensure that each book has a
unique identifier.
● Data Types: Choose appropriate data types for your fields (e.g., Number for Book_ID,
Short Text for Name and Status).
● Queries: Queries allow you to easily filter and retrieve specific data from your database.
7(a) C Program for Case Conversion
#include <stdio.h>
#include <ctype.h> // Include ctype.h for toupper() and tolower()

char changeCase(char ch) {


if (isupper(ch)) {
return tolower(ch);
} else if (islower(ch)) {
return toupper(ch);
} else {
return ch; // Return the character as is if it's not a letter
}
}

int main() {
char character, converted;

printf("Enter a character: ");


scanf(" %c", &character);

converted = changeCase(character);

printf("Converted character: %c\n", converted);

return 0;
}

Explanation:
● #include <ctype.h>: This line includes the ctype.h header file, which provides functions
for character manipulation, such as toupper() (convert to uppercase) and tolower()
(convert to lowercase).
● changeCase function: This function takes a character (ch) as input.
○ It uses isupper(ch) to check if the character is uppercase. If it is, it converts it to
lowercase using tolower(ch).
○ It uses islower(ch) to check if the character is lowercase. If it is, it converts it to
uppercase using toupper(ch).
○ If the character is not a letter, it returns the character unchanged.
● main function:
○ It takes a character as input from the user.
○ It calls the changeCase function to convert the character.
○ It prints the converted character.
7(b) MS Access Database for Student Attendance
This is the same as question 3(b). Here's the solution again:
i. Create Tables
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "AttendanceDB").
3. Create the "StudentInfo" table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ St_Address: (Short Text)
■ St_Phone: (Short Text)
■ St_Email: (Short Text)
4. Create the "Attendance" table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Attendance: (Short Text) - (e.g., "Present", "Absent", "Late")
ii. Create Relationship
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add both "StudentInfo" and "Attendance" tables to the Relationships
window.
4. Create Relationship:
○ Drag the St_ID field from the "StudentInfo" table to the St_ID field in the
"Attendance" table.
○ In the "Edit Relationships" dialog box, ensure "Enforce Referential Integrity" is
checked. Click "Create". This creates a one-to-one relationship between the tables.
iii. Search, Delete, and Update Records
● Search for St_ID:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "StudentInfo" table to the query.
3. Select Fields: Add the fields you want to display (e.g., St_ID, St_Name).
4. Add Criteria: In the St_ID column, enter the ID you want to search for in the
Criteria row.
5. Run the Query: Click "Run" to see the matching record.
● Delete a Student Record:
1. Open the Table: Open the "StudentInfo" table in Datasheet View.
2. Find the Record: Locate the record with the St_ID you want to delete.
3. Delete: Select the record and press the Delete key. (Referential integrity will delete
the related record in the "Attendance" table.)
● Update a Student Record:
1. Open the Table: Open the "StudentInfo" table in Datasheet View.
2. Find the Record: Locate the record with the St_ID you want to update.
3. Edit: Double-click the field you want to change and enter the new value.
Important Notes:
● Referential Integrity: Ensures data consistency by preventing accidental deletion or
modification of related data.
● Data Validation: You can add validation rules to the St_Attendance field to ensure only
valid values (e.g., "Present", "Absent", "Late") are entered.
● Forms: For a more user-friendly way to update and enter data, you can create forms in
Access.
8(a) C Program to Draw a Checkerboard
#include <stdio.h>

int main() {
int rows, cols;

printf("Enter the number of rows: ");


scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);

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


for (int j = 0; j < cols; j++) {
if ((i + j) % 2 == 0) {
printf("* "); // Or you can use a different character
} else {
printf(" "); // Two spaces for an empty square
}
}
printf("\n");
}

return 0;
}

Explanation:
● Input: The program takes the number of rows and cols for the checkerboard as input.
● Nested Loops: It uses nested for loops to iterate through each cell of the checkerboard.
The outer loop iterates through the rows, and the inner loop iterates through the columns.
● Checkerboard Pattern: The if ((i + j) % 2 == 0) condition creates the alternating pattern.
It checks if the sum of the row number (i) and column number (j) is even or odd. If it's
even, it prints a "*", otherwise it prints two spaces.
● Output: This code will print a checkerboard pattern to the console.
8(b) MS Access Database for Bank Accounts
This is the same as question 2(b). Here's the solution again:
i. Create Tables
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "BankDB").
3. Create the First Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "AccountInfo" table:
■ Acc_ID: (Number, Long Integer, set as Primary Key)
■ Acc_Name: (Short Text)
■ Acc_Address: (Short Text)
■ Acc_Phone: (Short Text)
■ Acc_Email: (Short Text)
4. Create the Second Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "AccountStatus" table:
■ Acc_ID: (Number, Long Integer, set as Primary Key)
■ Acc_Status: (Short Text) - (e.g., "Active", "Inactive", "Closed")
ii. Create Relationship
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add both "AccountInfo" and "AccountStatus" tables to the Relationships
window.
4. Create Relationship:
○ Drag the Acc_ID field from the "AccountInfo" table to the Acc_ID field in the
"AccountStatus" table.
○ In the "Edit Relationships" dialog box, ensure "Enforce Referential Integrity" is
checked. Click "Create". This creates a one-to-one relationship between the tables.
iii. Search and Delete Records
● Search for Acc_ID:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "AccountInfo" table to the query.
3. Select Fields: Add the fields you want to see in the results (e.g., Acc_ID,
Acc_Name).
4. Add Criteria: In the Acc_ID column, enter the ID you want to search for in the
Criteria row.
5. Run the Query: Click "Run" to see the matching record.
● Delete an Account:
1. Open the Table: Open the "AccountInfo" table in Datasheet View.
2. Find the Record: Locate the record with the Acc_ID you want to delete.
3. Delete: Select the record and press the Delete key. (Since you have referential
integrity, deleting from "AccountInfo" will also delete the corresponding record in
"AccountStatus").
Important Notes:
● Referential Integrity: Enforcing referential integrity helps maintain data consistency by
preventing accidental deletion of related records.
● Deleting Records: Be cautious when deleting records, as the action cannot be easily
undone.
● https://www.chegg.com/homework-help/questions-and-answers/8-consider-2d-array-take-i
nput-user-find-sum-main-diagonal-element-b-sum-border-elements-c-q100805131
9(a) C Program to Generate ASCII Characters
#include <stdio.h>

int main() {
int i;

printf("ASCII characters from 32 to 127:\n");

for (i = 32; i <= 127; i++) {


printf("%c ", i);

// Print a newline after every 16 characters


if ((i - 31) % 16 == 0) {
printf("\n");
}
}

printf("\n");
return 0;
}

Explanation:
● Loop: The for loop iterates through ASCII codes from 32 to 127 (inclusive).
● printf("%c ", i);: This line prints the character corresponding to the current ASCII code (i).
● Formatting: The if ((i - 31) % 16 == 0) condition is used to print a newline character (\n)
after every 16 characters, making the output more readable.
9(b) MS Access Database for Student Attendance
This is the same as question 3(b) and 7(b). Here's the solution again:
i. Create Tables
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "AttendanceDB").
3. Create the "StudentInfo" table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ St_Address: (Short Text)
■ St_Phone: (Short Text)
■ St_Email: (Short Text)
4. Create the "Attendance" table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Attendance: (Short Text) - (e.g., "Present", "Absent", "Late")
ii. Create Relationship
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add both "StudentInfo" and "Attendance" tables to the Relationships
window.
4. Create Relationship:
○ Drag the St_ID field from the "StudentInfo" table to the St_ID field in the
"Attendance" table.
○ In the "Edit Relationships" dialog box, ensure "Enforce Referential Integrity" is
checked. Click "Create". This creates a one-to-one relationship between the tables.
iii. Search, Delete, and Update Records
● Search for St_ID:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "StudentInfo" table to the query.
3. Select Fields: Add the fields you want to display (e.g., St_ID, St_Name).
4. Add Criteria: In the St_ID column, enter the ID you want to search for in the
Criteria row.
5. Run the Query: Click "Run" to see the matching record.
● Delete a Student Record:
1. Open the Table: Open the "StudentInfo" table in Datasheet View.
2. Find the Record: Locate the record with the St_ID you want to delete.
3. Delete: Select the record and press the Delete key. (Referential integrity will delete
the related record in the "Attendance" table.)
● Update a Student Record:
1. Open the Table: Open the "StudentInfo" table in Datasheet View.
2. Find the Record: Locate the record with the St_ID you want to update.
3. Edit: Double-click the field you want to change and enter the new value.
Important Notes:
● Referential Integrity: Ensures data consistency by preventing accidental deletion or
modification of related data.
● Data Validation: You can add validation rules to the St_Attendance field to ensure only
valid values (e.g., "Present", "Absent", "Late") are entered.
● Forms: For a more user-friendly way to update and enter data, you can create forms in
Access.
10(a) C Program to Read and Print Student Data
#include <stdio.h>

int main() {
char name[50];
int age;
float height;
char gender;

// Input using escape sequences for formatting


printf("Enter student details:\n");
printf("Name: ");
scanf("%s", name);

printf("Age: ");
scanf("%d", &age);

printf("Height (in cm): ");


scanf("%f", &height);

printf("Gender (M/F): ");


scanf(" %c", &gender); // Note the space before %c

// Output using escape sequences for formatting


printf("\n--- Student Information ---\n");
printf("Name: %s\n", name);
printf("Age: %d\n", age);
printf("Height: %.2f cm\n", height);
printf("Gender: %c\n", gender);

return 0;
}

Explanation:
● scanf("%s", name);: Reads the student's name.
● scanf(" %c", &gender);: The space before %c in scanf is important to consume any
leftover newline character from previous input.
● printf("\n--- Student Information ---\n");: \n is used to print a newline character for better
output formatting.
● printf("Height: %.2f cm\n", height);: %.2f is a format specifier to print the height with
two decimal places.
10(b) MS Access Database for Student Result Information
i. Create the Database and Table
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "StudentResultDB").
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ St_Marks: (Number, Integer)
4. Save the Table: Save the table as "Results".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Results" table.
2. Enter Data: Enter 10 records with student IDs, names, and marks. Make sure each
student has a unique St_ID.
iii. Sort Records
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Results" table to the query.
3. Select Fields: Drag all fields (St_ID, St_Name, St_Marks) to the query grid.
4. Sort: Click in the St_Marks column in the grid. In the "Sort" row, select "Descending".
5. Run the Query: Click "Run" to see the records sorted in descending order by marks.
iv. Display All Records
You can simply open the "Results" table in Datasheet View to see all the records. Or, you can
create a query that selects all fields from the table and run it.
Important Notes:
● Primary Key: The St_ID is the primary key to ensure each student has a unique identifier.
● Data Types: Choose appropriate data types for your fields.
● Sorting: You can sort records in queries by different fields and in ascending or
descending order.
● Queries: Queries provide a flexible way to retrieve and manipulate data.
11(a) C Program to Check for Prime Number
#include <stdio.h>

int main() {
int num, i, isPrime = 1; // Assume the number is prime initially

printf("Enter a positive integer: ");


scanf("%d", &num);

// Handle cases for 1, 2, and negative numbers


if (num <= 1) {
isPrime = 0;
} else if (num <= 3) {
isPrime = 1;
} else if (num % 2 == 0 || num % 3 == 0) {
isPrime = 0;
} else {
for (i = 5; i * i <= num; i = i + 6) {
if (num % i == 0 || num % (i + 2) == 0) {
isPrime = 0;
break;
}
}
}

if (isPrime) {
printf("%d is a prime number.\n", num);
} else {
printf("%d is not a prime number.\n", num);
}

return 0;
}

Explanation:
● Prime Number: A prime number is a natural number greater than 1 that has no positive
divisors other than 1 and itself.
● Optimization: The code includes optimizations to check divisibility by 2 and 3, and then
iterates with a step of 6 (optimized based on the fact that all prime numbers greater than 3
can be expressed in the form 6k ± 1).
● isPrime flag: This flag is used to keep track of whether the number is prime or not.
11(b) MS Access Database for Library
This is the same as questions 1(b) and 6(b). Here's the solution again:
i. Create the Database
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and give it a name like "LibraryDB".
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Book_ID: (Number, Long Integer, set as Primary Key)
■ Name: (Short Text)
■ Status: (Short Text) - This field will store "Issued" or "Available".
4. Save the Table: Save the table as "Books".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Books" table.
2. Enter Data: Enter 20 records with different book names. Make sure to assign a unique
Book_ID to each book and set the Status as "Issued" or "Available" accordingly.
iii. Queries
● Display Issued Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Issued" in the Criteria row.
5. Run the Query: Click "Run" to see the list of issued books.
● Display Available Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Available" in the Criteria row.
5. Run the Query: Click "Run" to see the list of available books.
Important Notes:
● Primary Key: The Book_ID is set as the primary key to ensure that each book has a
unique identifier.
● Data Types: Choose appropriate data types for your fields (e.g., Number for Book_ID,
Short Text for Name and Status).
● Queries: Queries allow you to easily filter and retrieve specific data from your database.
12(a) C Program to Print Squares and Cubes of Even Numbers
#include <stdio.h>

int main() {
int i;

printf("Number\tSquare\tCube\n");
printf("------\t------\t----\n");

for (i = 2; i <= 20; i += 2) { // Loop through even numbers from


2 to 20
printf("%d\t%d\t%d\n", i, i * i, i * i * i);
}

return 0;
}

Explanation:
● Loop: The for loop iterates through even numbers from 2 to 20 (inclusive) with a step of
2.
● Calculation: Inside the loop, the square (i * i) and cube (i * i * i) of the current even
number (i) are calculated.
● Output: The printf statement prints the number, its square, and its cube in a formatted
table.
12(b) MS Access Database for Bank Accounts
This is the same as questions 2(b) and 8(b). Here's the solution again:
i. Create Tables
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "BankDB").
3. Create the First Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "AccountInfo" table:
■ Acc_ID: (Number, Long Integer, set as Primary Key)
■ Acc_Name: (Short Text)
■ Acc_Address: (Short Text)
■ Acc_Phone: (Short Text)
■ Acc_Email: (Short Text)
4. Create the Second Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields to the "AccountStatus" table:
■ Acc_ID: (Number, Long Integer, set as Primary Key)
■ Acc_Status: (Short Text) - (e.g., "Active", "Inactive", "Closed")
ii. Create Relationship
1. Database Tools: Go to the "Database Tools" tab.
2. Relationships: Click "Relationships".
3. Add Tables: Add both "AccountInfo" and "AccountStatus" tables to the Relationships
window.
4. Create Relationship:
○ Drag the Acc_ID field from the "AccountInfo" table to the Acc_ID field in the
"AccountStatus" table.
○ In the "Edit Relationships" dialog box, ensure "Enforce Referential Integrity" is
checked. Click "Create". This creates a one-to-one relationship between the tables.
iii. Search and Delete Records
● Search for Acc_ID:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "AccountInfo" table to the query.
3. Select Fields: Add the fields you want to see in the results (e.g., Acc_ID,
Acc_Name).
4. Add Criteria: In the Acc_ID column, enter the ID you want to search for in the
Criteria row.
5. Run the Query: Click "Run" to see the matching record.
● Delete an Account:
1. Open the Table: Open the "AccountInfo" table in Datasheet View.
2. Find the Record: Locate the record with the Acc_ID you want to delete.
3. Delete: Select the record and press the Delete key. (Since you have referential
integrity, deleting from "AccountInfo" will also delete the corresponding record in
"AccountStatus").
Important Notes:
● Referential Integrity: Enforcing referential integrity helps maintain data consistency by
preventing accidental deletion of related records.
● Deleting Records: Be cautious when deleting records, as the action cannot be easily
undone.
13(a) C Program with Switch and Break
#include <stdio.h>

int main() {
int choice;

printf("Menu:\n");
printf("1. Calculate area of a circle\n");
printf("2. Calculate area of a rectangle\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1: {
float radius, area;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = 3.14159 * radius * radius;
printf("Area of the circle = %.2f\n", area);
break;
}
case 2: {
float length, width, area;
printf("Enter the length and width of the rectangle: ");
scanf("%f %f", &length, &width);
area = length * width;
printf("Area of the rectangle = %.2f\n", area);
break;
}
case 3:
printf("Exiting...\n");
break;
default:
printf("Invalid choice!\n");
}

return 0;
}

Explanation:
● switch (choice): The switch statement evaluates the value of the choice variable.
● case 1 and case 2: These cases calculate the area of a circle and rectangle respectively.
● case 3: This case exits the program.
● default: This case handles invalid choices.
● break: The break statement is used to exit the switch block after a case is executed.
13(b) MS Access Database for Student Information
i. Create the Database and Table
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "StudentInfoDB").
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ Class: (Short Text) - (e.g., "10th", "11th", "12th")
■ Group: (Short Text) - (e.g., "Pre-Engineering", "Pre-Medical", "Commerce")
■ Sex: (Short Text) - (e.g., "Male", "Female")
4. Save the Table: Save the table as "Students".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Students" table.
2. Enter Data: Enter 20 records with student information, including their ID, name, class,
group, and sex. Ensure each student has a unique St_ID.
iii. and iv. Queries
● Find Female Pre-Engineering Students:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Students" table to the query.
3. Select Fields: Drag the fields you want to display (e.g., St_ID, St_Name, Class) to
the query grid.
4. Add Criteria:
■ In the Group column, type "Pre-Engineering" in the Criteria row.
■ In the Sex column, type "Female" in the Criteria row.
5. Run the Query: Click "Run" to see the list of female pre-engineering students.
● Find Male Pre-Engineering Students:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Students" table to the query.
3. Select Fields: Drag the fields you want to display (e.g., St_ID, St_Name, Class) to
the query grid.
4. Add Criteria:
■ In the Group column, type "Pre-Engineering" in the Criteria row.
■ In the Sex column, type "Male" in the Criteria row.
5. Run the Query: Click "Run" to see the list of male pre-engineering students.
Important Notes:
● Primary Key: The St_ID is the primary key to ensure each student has a unique identifier.
● Data Types: Choose appropriate data types for your fields.
● Queries: Queries provide a flexible way to retrieve and filter data based on specific
criteria.
● https://github.com/SaiVarunKothi/cprogram-
● https://www.numerade.com/ask/question/write-a-c-program-to-program-an-external-comm
and-area-that-calculates-the-area-of-one-of-three-shapes-based-on-option-in-driven-men
u-r-or-r-find-the-area-of-rectangle-with-length-l-and-width-91548
● https://www.studysmarter.co.uk/explanations/computer-science/computer-programming/sc
anf-function-with-buffered-input/
● https://github.com/awkward-py/C-Programs
14(a) C Program to Print Pattern
#include <stdio.h>

int main() {
int rows = 5;

for (int i = 1; i <= rows; i++) {


for (int j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}

return 0;
}

Explanation:
● Outer Loop: The outer for loop controls the number of rows. It iterates from i = 1 to i =
rows (5 in this case).
● Inner Loop: The inner for loop controls the numbers printed in each row. It iterates from j
= 1 to j = i. This means it prints numbers from 1 up to the current row number.
● printf("%d ", j);: This line prints the value of j (the current number) followed by a space.
● printf("\n");: This line prints a newline character after each row is printed, moving the
output to the next line.
14(b) MS Access Database for Student Information
This is the same as question 13(b). Here's the solution again:
i. Create the Database and Table
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "StudentInfoDB").
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ Class: (Short Text) - (e.g., "10th", "11th", "12th")
■ Group: (Short Text) - (e.g., "Pre-Engineering", "Pre-Medical", "Commerce")
■ Sex: (Short Text) - (e.g., "Male", "Female")
4. Save the Table: Save the table as "Students".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Students" table.
2. Enter Data: Enter 20 records with student information, including their ID, name, class,
group, and sex. Ensure each student has a unique St_ID.
iii. and iv. Queries
● Find Female Pre-Engineering Students:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Students" table to the query.
3. Select Fields: Drag the fields you want to display (e.g., St_ID, St_Name, Class) to
the query grid.
4. Add Criteria:
■ In the Group column, type "Pre-Engineering" in the Criteria row.
■ In the Sex column, type "Female" in the Criteria row.
5. Run the Query: Click "Run" to see the list of female pre-engineering students.
● Find Male Pre-Engineering Students:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Students" table to the query.
3. Select Fields: Drag the fields you want to display (e.g., St_ID, St_Name, Class) to
the query grid.
4. Add Criteria:
■ In the Group column, type "Pre-Engineering" in the Criteria row.
■ In the Sex column, type "Male" in the Criteria row.
5. Run the Query: Click "Run" to see the list of male pre-engineering students.
Important Notes:
● Primary Key: The St_ID is the primary key to ensure each student has a unique identifier.
● Data Types: Choose appropriate data types for your fields.
● Queries: Queries provide a flexible way to retrieve and filter data based on specific
criteria.
15(a) C Program with Function to Calculate Sum
#include <stdio.h>

// Function to calculate the sum of two numbers


int sum1(int a, int b) {
return a + b;
}

int main() {
int num1, num2, result;

printf("Enter two numbers: ");


scanf("%d %d", &num1, &num2);

// Call the sum1 function and pass num1 and num2 as arguments
result = sum1(num1, num2);

printf("Sum of %d and %d is: %d\n", num1, num2, result);

return 0;
}

Explanation:
● sum1 Function: This function takes two integer arguments (a and b) and returns their
sum.
● main Function:
○ It takes two numbers as input from the user.
○ It calls the sum1 function, passing the input numbers as arguments.
○ It stores the result returned by sum1 in the result variable.
○ It prints the sum.
15(b) MS Access Database for Student Result Information
This is the same as question 10(b). Here's the solution again:
i. Create the Database and Table
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and name it (e.g., "StudentResultDB").
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ St_ID: (Number, Long Integer, set as Primary Key)
■ St_Name: (Short Text)
■ St_Marks: (Number, Integer)
4. Save the Table: Save the table as "Results".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Results" table.
2. Enter Data: Enter 10 records with student IDs, names, and marks. Make sure each
student has a unique St_ID.
iii. Sort Records
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Results" table to the query.
3. Select Fields: Drag all fields (St_ID, St_Name, St_Marks) to the query grid.
4. Sort: Click in the St_Marks column in the grid. In the "Sort" row, select "Descending".
5. Run the Query: Click "Run" to see the records sorted in descending order by marks.
iv. Display All Records
You can simply open the "Results" table in Datasheet View to see all the records. Or, you can
create a query that selects all fields from the table and run it.
Important Notes:
● Primary Key: The St_ID is the primary key to ensure each student has a unique identifier.
● Data Types: Choose appropriate data types for your fields.
● Sorting: You can sort records in queries by different fields and in ascending or
descending order.
● Queries: Queries provide a flexible way to retrieve and manipulate data.
16(a) C Program to Calculate Payroll
#include <stdio.h>

int main() {
float basic_pay, medical_allowance, conveyance_allowance,
house_rent;
float gp_fund, gross_pay, net_pay;

// Input basic pay


printf("Enter the basic pay: ");
scanf("%f", &basic_pay);

// Calculate allowances
medical_allowance = 0.15 * basic_pay;
conveyance_allowance = 0.20 * basic_pay;
house_rent = 0.45 * basic_pay;

// Calculate GP fund deduction


gp_fund = 0.07 * basic_pay;

// Calculate gross pay


gross_pay = basic_pay + medical_allowance + conveyance_allowance +
house_rent;

// Calculate net pay


net_pay = gross_pay - gp_fund;

// Print the results


printf("\n--- Payroll Details ---\n");
printf("Basic Pay: %.2f\n", basic_pay);
printf("Medical Allowance: %.2f\n", medical_allowance);
printf("Conveyance Allowance: %.2f\n", conveyance_allowance);
printf("House Rent: %.2f\n", house_rent);
printf("GP Fund Deduction: %.2f\n", gp_fund);
printf("Gross Pay: %.2f\n", gross_pay);
printf("Net Pay: %.2f\n", net_pay);

return 0;
}

Explanation:
● The program first takes the employee's basic_pay as input.
● It then calculates the medical_allowance, conveyance_allowance, and house_rent as
percentages of the basic pay.
● The gp_fund deduction is also calculated as a percentage of the basic pay.
● The gross_pay is calculated by adding the basic pay and all allowances.
● The net_pay is calculated by subtracting the GP fund deduction from the gross pay.
● Finally, the program prints a formatted payroll summary.
16(b) MS Access Database for Library
This is the same as questions 1(b), 6(b), and 11(b). Here's the solution again:
i. Create the Database
1. Open MS Access: Start Microsoft Access.
2. Create a New Database: Click "Blank database" and give it a name like "LibraryDB".
3. Create a Table:
○ Go to "Create" -> "Table Design".
○ Add the following fields:
■ Book_ID: (Number, Long Integer, set as Primary Key)
■ Name: (Short Text)
■ Status: (Short Text) - This field will store "Issued" or "Available".
4. Save the Table: Save the table as "Books".
ii. Input Records
1. Datasheet View: Switch to Datasheet View for the "Books" table.
2. Enter Data: Enter 20 records with different book names. Make sure to assign a unique
Book_ID to each book and set the Status as "Issued" or "Available" accordingly.
iii. Queries
● Display Issued Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Issued" in the Criteria row.
5. Run the Query: Click "Run" to see the list of issued books.
● Display Available Books:
1. Create a Query: Go to "Create" -> "Query Design".
2. Add Table: Add the "Books" table to the query.
3. Select Fields: Drag the Book_ID and Name fields to the query grid.
4. Add Criteria: In the Status column of the grid, type "Available" in the Criteria row.
5. Run the Query: Click "Run" to see the list of available books.
Important Notes:
● Primary Key: The Book_ID is set as the primary key to ensure that each book has a
unique identifier.
● Data Types: Choose appropriate data types for your fields (e.g., Number for Book_ID,
Short Text for Name and Status).
● Queries: Queries allow you to easily filter and retrieve specific data from your database.

You might also like