-->
Showing posts with label HISSAN. Show all posts
Showing posts with label HISSAN. Show all posts

Sunday, May 4, 2025

HISSAN computer science || Grade 12 Computer Science 2081 – Full Questions & Solutions

 

 

HISSAN CENTRAL EXAMINATION 2081 (2025)

Grade: XII Time: 2 hrs

F.M.: 50

COMPUTER SCIENCE (4281 M1)

Candidates are required to give their answers in their own words as far as practicable.

Multiple Choice Questions.

GROUP A
Writes the best alternative.

[9×1=9]

1.Which database language is used for defining schema structures?

a)DML                                                b)DDL

c)DCL                                                d)TCL

 

ans: b)DDL

 

2. Which of the following operations are used to extract data from a
database?

a)SELECT                                         b)DELETE

c)UPDATE                                         d)INSERT

 

ans: a)SELECT

3. Which of the following is NOT a valid PHP data type?

a)String                              b)Float

c)Character                      d)Boolean

 

ans: c)Character

4.Which symbol is used for single-line comments in JavaScript?

a)//                                      b)/* */

c)<!-- -->                            d)**

 

ans a)//

5.What is the default return type of a function in C if no return type is
specified?

a)void                                 b)int

c)char                                 d)float

 

Ans: b)int

6. Which network device is used to connect multiple networks together?

a)Hub                                                b)Switch

c)Router                                            d)Repeater

 

ans: c)Router

7. What is cloud computing?

a)A type of software                                                                                 b)A type of hardware

c)The delivery of computing services over the internet                d)A programming language

 

Ans: c)The delivery of computing services over the internet             

8. Which of the following is NOT a principle of OOP?

a)Encapsulation                            b)Inheritance

c) Compilation                                d)Polymorphism

 

Ans: c) Compilation

9.Which of the following SDLC models is also known as the "linear-
sequential model"?

a)Spiral Model                                b)Waterfall Model

c)Agile Model                                  d)V-Model

 

Ans: b)Waterfall Model

Short Answer Questions: 15×5-25]
GROUP B

10. What is database? Explain any three advantages of DBMS.                                             [2+3=5]

Ans:-

Database:-

It is a collection of interrelated data . These can be stored in the form of tables. A database can be of any size and varying complexity. A database may be generated and manipulated manually or it may be computerized. 

Example: 

Customer database consists the fields as cname, cno, and ccity.



DBMS:

The software tool package that helps gatekeeper and manage data storage, access and maintenances. It can be either in personal usage scope (MS Access, SQLite) or enterprise level scope (Oracle, MySQL, MS SQL, etc). 

DBMS advantages:-

1. Multiple users: 

DBMS allows us to share the data among many users and from different sites. It is done to enter multiple data and for the customers. For a complex database, we assign limited access control for them.

2. Backup: 

Backup means storing the data in different location or machines. It is done by users or the computers themselves to recover the data in the case of failure. Like reserving a ticket online, suppose 100 persons have reserved and the suddenly the system became down, Now what to do in this scenario, we need old data and new data both. Hence the administrator recovers the data from backup.

3.Data security:-

 Obviously, the data for an organization is crucial. What would happen if a hacker or unauthorized person uses it? Our data could be public and  misused by third persons for their own purpose. To avoid  that risk  we assign specific roles to users. We may filter incoming and outgoing data. For this the DBMS is helpful.


OR

Explain second normal form with example.                                                                                  [5]

Ans:-

Second normal form:-

A table is said to be in 2N if it satisfies the following conditions.
1. If it is in 1N.
2.If all non-key attributes are fully functionally dependent on entire primary key, not on only its part.

Example:
Let us consider the following table.

item

colors

price

tax

T-shirt

Red

13

0.45

T-shirt

Blue

13

0.45

polo

red

12

0.4


Here, the table is already in 1N. But it is not in 2N because non-key attributes price and tax depend on item not on colors which is a part of primary key(items, colors). This violates the rule for 2N as it says the non-key attribute is functionally depend on primary key fully, not partially.

To convert this into 2N, we are going to break this into two tables as given here.

items

item

colors

T-shirt

Red

T-shirt

Blue

polo

red


and

Tax

item

price

tax

T-shirt

13

0.45

T-shirt

13

0.45

polo

12

0.4


Now it is in 2NF.

11. Write a javascript function that takes two numbers as arguments and returns their sum.[5]

Ans:

<script>
                var a,b;
                function sum(a,b)
                {
            return a+b;
                }
                a=parseInt(prompt("enter a number for a"));
                b=parseInt(prompt("enter a number foor b"));
                document.write(sum(a,b));
        </script>

OR
Write a PHP script to find the largest of three numbers.

Ans:-

<?php
            $number1 = 10;
            $number2 = 25;
            $number3 = 15;
            if ($number1 >= $number2 && $number1 >= $number3) 
            {
                $greatest = $number1;
            
            elseif ($number2 >= $number1 && $number2 >= $number3)
             {
                $greatest = $number2;
            
            else 
            {
                $greatest = $number3;
                }
        echo "The greatest number is: " . $greatest;
?>


12. Explain the concept of inheritance in OOP. How does inheritance help in code reusability?[2+3]

Ans:-

Inheritance:-

                   It is the fundamental concept in OOP programming paradigm. As the name says, we derive some new classes from existing classes. The class we derive from is called main class or super class where as the derived class is called child class or sub class. This derivation helps us to use the properties and methods of parent class by child class. This feature helps us to use the code of parent class by child class without re-writing the code.

second part:
This feature helps us in code re-usability  in following way.
1.Reusing the code: Since  inheritance allows us to use the property and method of suer class, we do not need to write them again and again. So it saves our time. Example: multiple vehicle types(car and truck) share common property from class vehicle.
2.Extensibility: Subclasses can extend the super class by adding new property and methods. Not only that much,  we can add new classes as per demand without modifying existing ones.
3.Easier maintenance: Changes in the parent classes automatically apply to all child classes, making  update easier and consistent.

13 What is e-learning? Write any three advantages of e-learning.                                        [2+3]

Ans:-

e-learning:-

E-LEARNING is a flexible term used to describe a means of teaching through technology such as a network, browser, CDROM or DVD multimedia platforms. In today's world, mostly, we use internet to learn or teach or share the contents. We do not need to be in a fixed location  to learn. It is just like learn 'wherever you go'

Advantages:

1. Availability of same course to millions. 

2. Boon for Working class. 

3. Apprehensive Employers. 


14. What is the purpose of the requirements gathering phase in the SDLC? Explain. [2+3]

 Ans:-

The primary purpose of requirement gathering in SDLC is to accumulate, analyze and document requirements and assumptions of clients/stakeholders for whom possibly system is being developed. In this phase the development team becomes very clear about what is to be provided from the client side, and at later phase helps in defining requirements adhering to the same.

The main reasons to understand requirement can be:

Clarity and Scope Definition:
It simply defines the project scope, functionalities, constraints, and user expectations clearly, avoiding misunderstandings later in the development process.

Foundation for Design and Development:
The gathered requirements serve as the foundation for the system design, development, and testing phases. Accurate requirements ensure that the system is built as per user needs.

Cost and Time Management:
Well-defined requirements help in estimating project cost, time, and resources effectively, reducing the risk of scope creep, rework, and project failure.

Long Answer Questions: [2x8-16]
GROUP C

15.What is computer network? Explain any three types of network topologies with their advantages.
[2+6]

Ans:-
Computer network:-
A computer network, often simply referred to as a network, is a collection of computers and devices connected by communications channels that facilitates communications among users and allows users to share resources with other users. Networks may be classified according to a wide variety of characteristics.

Purpose of networking:-

  • Networking for communication medium (have communication among people;internal or external)
  • Resource sharing (files, printers, hard drives, cd-rom/)
  • Higher reliability ( to support a computer by another if that computer is down)
  • Higher flexibility( different system can be connected without any problems)
  • Scalable (computers and devices can be added with time without changing original network.

Topology:

When we go for networking, we connect some computers in particular layout or design. This design or pattern of connection is called topology.

There are many types;

Bus topology:

A linear bus topology consists of a main run of cable with a terminator at each end (See fig. 1). All nodes (file server, workstations, and peripherals) are connected to the linear cable.


Fig. 1. Linear Bus topology

Advantages of a Linear Bus Topology

  • Installation is easy and cheap to connect a computer or peripheral to a linear bus.

  • Requires less cable length than a star topology.


Star topology:-

A star topology is designed with each node (file server, workstations, and peripherals) connected directly to a central network hub, switch, or concentrator (See fig. 2).
Data on a star network passes through the hub, switch, or concentrator before continuing to its destination. The hub, switch, or concentrator manages and controls all functions of the network.
It also acts as a repeater for the data flow. This configuration is common with twisted pair cable; however, it can also be used with coaxial cable or fiber optic cable.

                Fig. 2. Star topology

Advantages of a Star Topology

  • Easy to install and wire.

  • No disruptions to the network when connecting or removing devices.

  • Easy to detect faults and to remove parts.

Mesh topology

The mesh topology incorporates a unique network design in which each computer on the network connects to every other, creating a point-to-point connection between every device on the network. The purpose of the mesh design is to provide a high level of redundancy.

It needs/uses n(n-1)/2 channels(paths) and n-1 input/ output ports. If one network cable fails, the data always has an alternative path to get to its destination.


Advantages:
  • Provides redundant paths between devices
  • The network can be expanded without disruption to current users.

16. Write a C program to read and display employee details using a structure. [Define a structure Employee to store employee name (string), ID (integer), and salary (float)]. Write a program to input values for these fields and then display them.

Ans:
#include <stdio.h>
struct Employee 
{
    char name[50];
    int id;
    float salary;
};
int main()
{
    struct Employee emp;
    printf("Enter employee name: ");
    gets(emp.name);
    printf("Enter employee ID: ");
    scanf("%d", &emp.id);
    printf("Enter employee salary: ");
    scanf("%f", &emp.salary);
    printf("\n--- Employee Details are:---\n");
    printf("Name   : %s\n", emp.name);
    printf("ID     : %d\n", emp.id);
    printf("Salary : %.2f\n", emp.salary);
    return 0;
}

OR

What is pointer? Write a C program to add two numbers using call by reference.                          [2+6]

Ans:-

Pointer:-

A pointer is a specific variable that stores the memory address in C of another variable. Rather than keeping a data value directly, a pointer keeps the address where the value is saved in memory. Because they allow us to access and change variables indirectly using their addresses, pointers are powerful.

Syntax:

return type * variable name;

Example:
int *pt;

Second part:-

#include <stdio.h>
void addNumbers(int *, int *) ;
int main() 
{
    int num1, num2;
    printf("Enter first number: ");
    scanf("%d", &num1);
    printf("Enter second number: ");
    scanf("%d", &num2);
    addNumbers(&num1, &num2);
    return 0;
}
void addNumbers(int *a, int *b) 
{
    int sum;
    sum = *a + *b;
  printf("the sum is:%d",sum);
}


THE END

Monday, March 20, 2023

HISSAN grade 12 computer science question 2079

 

HISSAN CENTRAL EXAMINATION - 2079 (2023)

 

Grade: XII                                                                                                                   Time: 2 hrs

Subject:- COMPUTER SCIENCE (TH) [4281 A]                                                    Full Marks: 50

 


GROUP A [9×1=9]


Multiple Choice Questions. 

Choose the correct answer.

1. In which normal form of database transitive dependency should not be occurred?

A)   First

B) second

C) Third

d) All of above

2. Which of the following techniques is used to grant privileges to user in a database?

A)   Authentication

B) Authorization

C) Isolation

D) Backup

3. Which SQL command is used to display all the records from a table named STUDENT with "H" as the first letter in the field FNAME (FIRST NAME)?

A) SELECT * FROM STUDENT WHERE FNAME LIKE "H";

B) SELECT * FROM STUDENT WHERE FNAME LIKE "%H%";

C) SELECT * FROM STUDENT WHERE FNAME LIKE "H%";

D) SELECT * FROM STUDENT WHERE FNAME LIKE "H";

4. Which of the following is a remote login service?

A) FTP

B)Telnet

C) SMTP

 D) All of the above

5. Which of the following is a server-side scripting language?

A)   PHP

B) MySql

C) JavaScript

D) SQL

6. Which of the following keywords are used to declare a variable in JavaScript?

A) int or suppose

B) float or int

C) var or let

D) char or var

7. What will be the result of combining a string with another data type in PHP?

A)   Float

B) int

C) string

D) double

8. The process of hiding internal details of a program and exposing the functionality is .....

A) Class.

B) Polymorphism.

C) Inheritance

D) Data Abstraction.

9. Which of the following is not a phase of SDLC?

A) Analysis.

B) Developing

C) Testing

D) Meeting

 

GROUP B [5x5=25]

Short Answer Questions

10. Suppose you are appointed as an IT expert in a Hotel. What kind of database system you preferred and why?                                                                                                                                                        [1+4]

OR

Most of the Hospitals prefer applying a relational database model for database design compared to other models. Justify the statement with     your arguments.                                                                                 [5]

11. Write a program in JavaScript to add the values of any two variables.                                              [5]

OR

How can you connect MYSQL database with PHP? Demonstrate with an example.                             [5]

12. Differentiate between OOP and procedural oriented language.                                                         [5]

13. State various stages of SDLC and explain any two.                                                                           [5]

14. Explain mobile computing with advantages.                                                                             [1+2+2]

GROUP C [2x8=16]

Long Answer Questions

15. Suppose you are appointed as an IT expert of any bank which network architecture you prefer and why?                                                                                                                                                   [2+6]

16. Write a program in C using structure to enter the roll_number, name, and marks scored in english, computer, maths and nepali of 10 students. Also, display them in proper format along with the total

marks. [Note: the marks should be between 0 and 100].                                                                          [8]

OR

Write a program in C to create and store name, gender, and phoneno of students to a data file named "ADDRESS.DAT". The program should prompt the user whether to continue or not. The program should also display all the records in the proper format.                                                                                       [8]

 

THE END

-----------------------------------------------------------------------------------------------------------

Answer key:

1.) c 2).B 3.) C 4.) D 5.) A 6.) C 7) C 8.)D 9.) D

--------------------------------------------------------------------------------------------------------------

Solutions:

 

HISSAN CENTRAL EXAMINATION - 2079 (2023)

 

Grade: XII                                                                                                                   Time: 2 hrs

Subject:- COMPUTER SCIENCE (TH) [4281 A]                                                    Full Marks: 50

 


GROUP A [9×1=9]


Multiple Choice Questions. 

Choose the correct answer.

1. In which normal form of database transitive dependency should not be occurred?

A)   First

B) second

C) Third

d) All of above

2. Which of the following techniques is used to grant privileges to user in a database?

A)   Authentication

B) Authorization

C) Isolation

D) Backup

3. Which SQL command is used to display all the records from a table named STUDENT with "H" as the first letter in the field FNAME (FIRST NAME)?

A) SELECT * FROM STUDENT WHERE FNAME LIKE "H";

B) SELECT * FROM STUDENT WHERE FNAME LIKE "%H%";

C) SELECT * FROM STUDENT WHERE FNAME LIKE "H%";

D) SELECT * FROM STUDENT WHERE FNAME LIKE "H";

4. Which of the following is a remote login service?

A) FTP

B)Telnet

C) SMTP

 D) All of the above

5. Which of the following is a server-side scripting language?

A)   PHP

B) MySql

C) JavaScript

D) SQL

6. Which of the following keywords are used to declare a variable in JavaScript?

A) int or suppose

B) float or int

C) var or let

D) char or var

7. What will be the result of combining a string with another data type in PHP?

A)   Float

B) int

C) string

D) double

8. The process of hiding internal details of a program and exposing the functionality is .....

A) Class.

B) Polymorphism.

C) Inheritance

D) Data Abstraction.

9. Which of the following is not a phase of SDLC?

A) Analysis.

B) Developing

C) Testing

D) Meeting

 

GROUP B [5x5=25]

Short Answer Questions

10. Suppose you are appointed as an IT expert in a Hotel. What kind of database system you preferred and why?    

Ans:-

If I were appointed as an IT expert in a hotel, I would prefer using a Relational Database Management System (RDBMS) such as MySQL, PostgreSQL, or Oracle for the hotel’s data management needs. Reasons for Preferring RDBMS:
  1. Structured Data Storage:
    Hotel operations involve structured data like guest records, room bookings, billing, inventory, staff details, etc. RDBMS stores this data in well-organized tables with clear relationships.

  2. Data Integrity and Accuracy:
    RDBMS supports constraints and data validation, ensuring data accuracy (e.g., no duplicate bookings or invalid guest entries).

  3. Easy Querying and Reporting:
    Using SQL, we can quickly generate reports like available rooms, guest check-ins, or billing summaries, helping in fast decision-making.

  4. Multi-user Access:
    Multiple departments (reception, kitchen, housekeeping, accounts) can access and update data simultaneously without conflicts.

  5. Security and Backup:
    RDBMS provides user roles and permissions, securing sensitive data. It also supports regular backups and recovery options.

                                                                                                                                             [1+4]

OR

Most of the Hospitals prefer applying a relational database model for database design compared to other models. Justify the statement with     your arguments.                           

Ans:-

Most hospitals prefer using the Relational Database Model (RDBMS) for database design due to the following strong reasons:

1. Structured and Organized Data Storage

Hospitals deal with structured data such as patient records, doctor information, lab reports, billing, appointments, etc. The relational model allows storing this data in tables with rows and columns, making it easy to manage and retrieve.

2. Data Integrity and Accuracy

RDBMS supports primary keys, foreign keys, and constraints, ensuring that data is consistent, accurate, and free from duplication. For example, each patient has a unique ID, and their test reports or prescriptions are linked properly.

3. Easy Data Retrieval Using SQL

RDBMS supports Structured Query Language (SQL), which helps hospital staff retrieve and analyze data quickly — like finding patient history, generating reports, or checking doctor schedules.

4. Security and Role-Based Access

Relational databases provide user roles and permissions to control who can view or modify data. This is crucial in hospitals where patient data privacy and data security are highly important.

5. Multi-user and Concurrent Access

Multiple departments (e.g., OPD, billing, pharmacy, lab) can access and update the same database simultaneously without conflicts, making hospital operations smoother and more efficient.

 6. Scalability and Maintenance

As hospital data grows over time, relational databases can easily scale and be maintained. Tables can be added or modified without affecting existing data relationships.  [5]

11. Write a program in JavaScript to add the values of any two variables.                                                                                                                                                                                                              [5]

Ans:-

<script>

let a = 10;

let b = 20;

let sum = a + b;

console.log("The sum of a and b is: " + sum);

</script>

OR

How can you connect MYSQL database with PHP? Demonstrate with an example.                             [5]

Ans:-

The mysqli_connect() function is used to establish a connection to a MySQL database using the MySQLi (MySQL Improved) extension in PHP.

Syntax:

mysqli_connect(host, username, password, database, port, socket);

  Here, port and socket are optional.  all other parameters' meaning are given below.
ParameterDescription
hostThe hostname or IP address of the MySQL server (e.g., "localhost").
usernameMySQL username (e.g., "root").
passwordPassword for the MySQL user. Mostly it is empty.
databaseName of the database to connect to.

Example:

         <?php

$connection = mysqli_connect("localhost", "root", "", "school");

if (!$connection) {

    die("Connection failed: " . mysqli_connect_error());

}

echo "Connected successfully";

?>

12. Differentiate between OOP and procedural oriented language.                                                         [5]

Ans:-

Procedural Oriented Language(POP):-

 Procedure oriented programming basically consists of writing a list of instructions(or actions) for the computer to follow, and organizing these instructions into groups known as functions. While we concentrate on the development , very little attention is given to the data that are being used by various functions.

            Diagrammatically we can show POP as 

 

Some characteristics (features) of Procedure Oriented Programming are :-

1) Emphasis is on doing things(algorithms).

2) Large programs are divided into smaller programs known as functions.

3) Most of the functions share global data.

4) Data more openly around the system from function to function.

5) Functions transform data from one form to another.

6) Employs a top-down approach in program design.


OOP(Object Oriented Programming):-

The major motivating factor in the invention of object oriented is to remove some of the flaws encountered in the procedural oriented approach. Object oriented programming uses concept of “Object” and treats data as a critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it, and protects it from accidental modifications from outside functions.

Some characteristics (features) of Object Oriented Programming are :-

1) Emphasis is on data rather than procedures or algorithms.

2) Programs are divided into what are known as objects.

3) Data structures are designed such that characterize the objects.

4) Functions that operate on the data are tied together in the data structure.

5) Data is hidden and cannot be accessed by external functions.

6) Objects may communicate with each other through functions.

7) New data and functions can be easily added whenever necessary.

8) Follows bottom-up approach in program design.

13. State various stages of SDLC and explain any two.                                                                           [5]

Ans:-

The Software Development Life Cycle (SDLC) consists of several phases that guide the process of developing high-quality software. The main stages are:


  1. Requirement gathering/planning

  2. Requirement Analysis

  3. System Design

  4. development(coding)

  5. Testing

  6. Implementation /deployment

  7. Maintenance

Here's a brief explanation of Analysis and Development phases in SDLC:

Analysis Phase:

In the analysis phase, the goal is to understand the exact requirements of the software system. This involves gathering information from clients or users to identify what the system should do. The result is a requirement specification document that guides the rest of the development process.

Development (Implementation) Phase:

In the development phase, the actual coding of the software takes place. Based on the design documents, developers write code using suitable programming languages. This is where the system starts to take shape as a working product.


14. Explain mobile computing with advantages.                                                                             [1+2+2]

Ans:-

Mobile computing:-

Mobile computing refers to the ability to use computing devices such as smartphones, tablets, and laptops wirelessly and on-the-go, allowing users to access data and perform tasks without being tied to a fixed location.

Some advantages of mobile computing are:

Advantages of Mobile Computing:

  1. Increased Flexibility:
    Users can access applications, data, and services from any location, allowing them to work remotely and manage tasks on the go.

  2. Real-time Communication:
    Mobile computing allows for instant communication through emails, messaging apps, and video calls, which is crucial for quick decision-making and collaboration.

  3. Improved Productivity:
    Mobile devices like smartphones and tablets allow users to complete tasks and access information quickly, helping professionals stay productive even while traveling or outside the office.

  4. Cost Efficiency:
    Mobile computing reduces the need for physical office setups and infrastructure, as employees can work remotely, leading to lower operational costs for businesses.


GROUP C [2x8=16]

Long Answer Questions

15. Suppose you are appointed as an IT expert of any bank which network architecture you prefer and why?                                                                                                                                                   [2+6]

Ans:-

If I were appointed as an IT expert for a bank, I would prefer the Client-Server Architecture for the bank's network. This is a widely used and suitable architecture for banks due to its security, scalability, and efficient management.

Reasons for Preferring Client-Server Architecture are:

1.Centralized Management:
Client-Server architecture allows for centralized control over all data and applications. The bank’s critical data (such as transaction records, account details, etc.) is stored on secure, centralized servers, making it easier to manage and backup information efficiently.

2.Data Security:

Banks deal with sensitive financial data. In a client-server setup, data access can be strictly controlled and monitored. Security protocols like firewalls, encryption, and access control mechanisms can be implemented at the server level to ensure safe transmission and storage of customer data.


3.Scalability:
The Client-Server architecture supports easy scalability. As the bank grows or experiences more traffic, the system can be expanded by adding more servers or upgrading server capacity to meet increased demands without disrupting services.

4.Reliable Communication and Data Flow:
Client-server systems ensure that client devices (e.g., ATMs, desktop terminals) securely interact with the central server, ensuring fast and reliable data processing. For example, a customer’s request at an ATM or bank terminal will be processed efficiently by the server.

5.High Availability and Redundancy:
Banks cannot afford downtime. With multiple servers and redundant systems, client-server architecture ensures high availability and backup servers in case of failure, ensuring uninterrupted banking services.

6.Easy Maintenance and Updates:
Updates and maintenance are easier to implement in a client-server model because the server is the centralized hub. Software updates, security patches, and new features can be deployed on the server and automatically reflected on all client devices, reducing operational complexity.

16. Write a program in C using structure to enter the roll_number, name, and marks scored in english, computer, maths and nepali of 10 students. Also, display them in proper format along with the total

marks. [Note: the marks should be between 0 and 100].                                                                          [8]

Ans:-

#include <stdio.h>

#include <string.h>

#define STUDENTS 10

struct Student 

{

    int roll_number;

    char name[50];

    int english;

    int computer;

    int maths;

    int nepali;

    int total;

};

int main() 

{

    struct Student s[STUDENTS];

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

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

        printf("Roll Number: ");

        scanf("%d", &s[i].roll_number);

        printf("Name: ");

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

        do {

            printf("Marks in English (0-100): ");

            scanf("%d", &s[i].english);

        } while (s[i].english < 0 || s[i].english > 100);

        do {

            printf("Marks in Computer (0-100): ");

            scanf("%d", &s[i].computer);

        } while (s[i].computer < 0 || s[i].computer > 100);

        do {

            printf("Marks in Maths (0-100): ");

            scanf("%d", &s[i].maths);

        } while (s[i].maths < 0 || s[i].maths > 100);

        do {

            printf("Marks in Nepali (0-100): ");

            scanf("%d", &s[i].nepali);

        } while (s[i].nepali < 0 || s[i].nepali > 100);

        s[i].total = s[i].english + s[i].computer + s[i].maths + s[i].nepali;

    }

    printf("\n%-5s %-20s %-8s %-9s %-7s %-8s %-6s\n", "Roll", "Name", "English", "Computer", "Maths", "Nepali", "Total");

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


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

        printf("%-5d %-20s %-8d %-9d %-7d %-8d %-6d\n",

            s[i].roll_number,

            s[i].name,

            s[i].english,

            s[i].computer,

            s[i].maths,

            s[i].nepali,

            s[i].total

        );

    }

    return 0;

}


OR

Write a program in C to create and store name, gender, and phoneno of students to a data file named "ADDRESS.DAT". The program should prompt the user whether to continue or not. The program should also display all the records in the proper format.                                                                                       [8]

 Ans:-

#include<stdio.h>

int main()

{

char name[100];

char gender[20];

int phone_no;

char choice='y';

FILE *p;

p=fopen("address.dat","w+");

while(choice!='n')

{

printf("enter name\n");

scanf("%s",&name);

printf("enter gender\n");

scanf("%s",&gender);

printf("enter phone number\n");

scanf("%d",&phone_no);

fprintf(p,"%s\t%s\t%d\n",name,gender,phone_no);

printf("enter y to continue and n to discontinue");

fflush(stdin);

scanf("%c",&choice);

}

rewind(p);

while((fscanf(p,"%s%s%d",name,gender,&phone_no))!=EOF)

{

printf("name =%s\n",name);

printf("gender=%s\n",gender);

printf("phone number=%d\n",phone_no);

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

}

fclose(p);

return 0;

}

THE END

-----------------------------------------------------------------------------------------------------------

Answer key:

1.) c 2).B 3.) C 4.) D 5.) A 6.) C 7) C 8.)D 9.) D