Sunday, February 2, 2025

C PROGRAMMING Solutions - SEE COMPUTER SCIENCE 2081

 


C PROGRAMMING Solutions

1.      Write a C program to find the average of any two numbers given by the user.

 

#include<stdio.h>

#include<conio.h>

int main()

{

    int a,b;

    float c;

    printf("Enter first number: ");

    scanf("%d", &a);

    printf("Enter second number: ");

    scanf("%d", &b);

    c=(a+b)/2;

    printf("Average of two numbers= %.2f",c);

    return 0;

}

 

2.      Write a C program to calculate the average of three numbers.

 

#include<stdio.h>

#include<conio.h>

int main()

{

    int a,b,c;

    float d;

    printf("Enter first number: ");

    scanf("%d", &a);

    printf("Enter second number: ");

    scanf("%d", &b);

    printf("Enter second number: ");

    scanf("%d", &c);

    d=(a+b+c)/3;

    printf("Average of two numbers= %.2f",d);

    return 0;

}

3.      Write a C program to calculate the volume of a cylinder.

#include<stdio.h>

#include<conio.h>

int main()

{

float r, h, v;

printf("Enter radius and height: \n");

scanf("%f %f", &r, &h);

v=(22/7)*r*r*h;

printf("Volume of cylinder= %.2f",v);

return 0;

}

 

4.      Write a C program to calculate distance travelled by a body.

 

#include<stdio.h>

#include<conio.h>

int main()

{

float u, a, s;

int t;

printf("Enter initial velocity: ");

scanf("%f", &u);

printf("Enter acceleration: ");

scanf("%f", &a);

printf("Enter time: ");

scanf("%d", &t);

s=(u*t)+(a*t*t)/2;

printf("Distance travelled by body= %.2f", s);

 

return 0;

}

 

5.      Write a C program using to get radius of circle and then print its area.

#include<stdio.h>

#include<conio.h>

int main()

{

float r, a;

printf("Enter radius: ");

scanf("%f", &r);

a=(22/7)*r*r;

printf("Area of circle= %.2f", a);

return 0;

}

 

6.      Write a C program to calculate and print the volume of a box.

#include<stdio.h>

#include<conio.h>

int main()

{

int l,b,h,v;

printf("Enter length: ");

scanf("%d", &l);

printf("Enter breadth: ");

scanf("%d", &b);

printf("Enter height: ");

scanf("%d", &h);

v=l*b*h;

printf("Volume of box= %d", v);

return 0;

}

 

7.      Write a C program to get radius of a circle and then print its circumference.

 

#include<stdio.h>

#include<conio.h>

int main()

{

float r, c;

printf("Enter radius: ");

scanf("%f", &r);

c=2*(22/7)*r;

printf("Circumference of circle= %.2f", c);

return 0;

}

 

8.      Write a C program to calculate the area of four walls.

 

#include<stdio.h>

#include<conio.h>

int main()

{

int l,b,h,a;

printf("Enter length: ");

scanf("%d", &l);

printf("Enter breadth: ");

scanf("%d", &b);

printf("Enter height: ");

scanf("%d", &h);

a=2*h*(l+b);

printf("Area of four walls= %d", a);

return 0;

}

 

9.      Write a C program in QBASIC to find the total surface area of a box.

 

#include<stdio.h>

#include<conio.h>

int main()

{

int l,b,h,a;

printf("Enter length: ");

scanf("%d", &l);

printf("Enter breadth: ");

scanf("%d", &b);

printf("Enter height: ");

scanf("%d", &h);

a=2*((l*b)+(b*h)+(h*l));

printf("Total surface area of box= %d", a);

return 0;

}

 

10.   Write a C program to calculate and print the simple interest.

#include<stdio.h>

#include<conio.h>

int main()

{

float p, t, r, i;

printf("Enter principal: ");

scanf("%f", &p);

printf("Enter time: ");

scanf("%f", &t);

printf("Enter rate: ");

scanf("%f", &r);

i = (p*t*r)/100;

printf("Simple Interest = %.2f", i);

return 0;

}

11.   Write a C program to get temperature in celsius from the user and then print the temperature in fahrenheit.

#include<stdio.h>

#include<conio.h>

int main()

{

 float c, f;

 

     printf("Enter temperature in Celsius: ");

     scanf("%f", &c);

     f = ((c * 9)/5) + 32;

     printf("%.2f Celsius = %.2f Fahrenheit", c, f);

 return 0;

}

 

12.   Write a C program to find the area of triangle.

#include<stdio.h>

#include<conio.h>

int main()

{

int b,h;

float a;

printf("Enter base: ");

scanf("%d", &b);

printf("Enter height: ");

scanf("%d", &h);

a=(b*h)/2;

printf("Area of triangle= %.2f", a);

return 0;

}

 

13.   Write a C program to get temperature in fahrenheit from the user and then print the temperature in celcius.

 

#include <stdio.h>

#include<conio.h>

int main()

{

    float c, f;

    printf("Enter temperature in Fahrenheit: ");

    scanf("%f", &f);

    c = (f - 32) * 5 / 9;

    printf("%.2f Fahrenheit = %.2f Celsius", f, c);

    return 0;

}

14.   Write a C program to convert USD(dollar) into NC (NEPALI currency).

#include<stdio.h>

#include<conio.h>

int main()

{

int d, n;

printf("Enter currency in dollar: ");

scanf("%d", &d);

n=d*100;

printf("$ %d = Rs. %d ", d, n);

 

return 0;

}

15.   Write a C program to convert NC (NEPALI currency) into IC (Indian Currency)

#include<stdio.h>

#include<conio.h>

int main()

{

float i, n;

printf("Enter currency in Nepali Rupees: ");

scanf("%f", &n);

i=n/1.6;

printf("Nrs. Rs %.2f = IC Rs. %.2f ", n, i);

 

return 0;

}

16.   WRITE A C PROGRAM  to display whether the given number is positive, negative or zero.

#include<stdio.h>

#include<conio.h>

int main()

{

int n;

printf("Enter any number: ");

scanf("%d", &n);

if(n>0)

printf("%d is positive number",n);

else if(n<0)

printf("%d is negative number",n);

else

printf("%d is zero number",n);

return 0;

}

17.   Write a C program to test whether the given number is completely divisible by 13 or not.

#include<stdio.h>

#include<conio.h>

int main()

{

int n;

printf("Enter any number: ");

scanf("%d", &n);

if(n%2==0)

printf("%d is divisible by 13",n);

else

printf("%d is not divisible by 13",n);

return 0;

}

18.   WRITE A C PROGRAM  to check whether the given number is divisible by 3 and 5 or not.

#include<stdio.h>

#include<conio.h>

int main()

{

int n;

printf("Enter any number: ");

scanf("%d", &n);

if(n%3==0 && n%5==0)

printf("%d is divisible by 3 and 5",n);

else

printf("%d is not divisible by 3 and 5",n);

return 0;

}

19.   WRITE A C PROGRAM  to enter age and display whether a person can vote or not.

 

#include<stdio.h>

#include<conio.h>

int main()

{

int a;

printf("Enter your age: ");

scanf("%d", &a);

if(a>=18)

printf("You can vote");

else

printf("You cannot vote");

return 0;

}

 

 

20.   Write a C program to display the smaller among two numbers.

 

#include<stdio.h>

#include<conio.h>

int main()

{

int a,b;

printf("Enter any two numbers:\n ");

scanf("%d %d", &a, &b);

if(a<b)

printf("The smaller number is %d", a);

else

printf("The smaller number is %d", b);

return 0;

}

21.   Write a C program to input three different and find the greatest number.

#include<stdio.h>

#include<conio.h>

int main()

{

int a,b,c;

printf("Enter any three numbers:\n ");

scanf("%d %d %d" , &a, &b, &c);

if(a>b && a>c)

printf("The greatest number is %d", a);

else if(b>a && b>c)

printf("The greatest number is %d", b);

else

printf("The greatest number is %d", c);

return 0;

}

22.   WRITE A C PROGRAM  to display middle number among three different numbers.

#include<stdio.h>

#include<conio.h>

int main()

{

int a,b,c;

printf("Enter any three numbers:\n ");

scanf("%d %d %d" , &a, &b, &c);

if((a>b && a<c) || (a<b && a>c))

printf("The middle number is %d", a);

else if((b>a && b<c) || (b<a && b>c))

printf("The middle number is %d", b);

else

printf("The middle number is %d", c);

return 0;

}

23.   Write a C program to check whether the given number is odd or even.

#include<stdio.h>

#include<conio.h>

int main()

{

int n;

printf("Enter any number: ");

scanf("%d", &n);

if(n%2==0)

printf("%d is even number", n);

else

printf("%d is odd number", n);

return 0;

}

 

24.   WRITE A C PROGRAM  to check whether the given year is leap year or not.

 

#include<stdio.h>

#include<conio.h>

int main()

{

int y;

printf("Enter the year: ");

scanf("%d", &y);

if((y%2==0) && (y%100 !=0) || (y%400==0))

printf("%d is leap year", y);

else

printf("%d is not leap year", y);

return 0;

}

25.   WRITE A C PROGRAM  to check whether the given number is perfect square or not.

#include<stdio.h>

#include<conio.h>

int main()

{

int n, b;

float a;

printf("Enter any number: ");

scanf("%d", &n);

a=sqrt(n);

b=a;

if(a==b)

printf("%d is a perfect square number", n);

else

printf("%d is not a perfect square number", n);

return 0;

}

 

 

26.   Write a C program to print the following series 9,7,5,…1.

#include<stdio.h>

#include<conio.h>

int main()

{

int i;

for(i=9;i>=1;i=i-2)

{

    printf("%d \n", i);

}

return 0;

}

27.   Write a C program to print the series 1,1,2,3,5,8… upto ten terms.

#include<stdio.h>

#include<conio.h>

int main()

{

int a,b,c,i;

a=1;

b=1;

for(i=1;i<=10;i++)

{

    printf("%d \n", a);

    c=a+b;

    a=b;

    b=c;

}

return 0;

}

28.   Write a C program to print natural numbers from 1 to 5.

#include<stdio.h>

#include<conio.h>

int main()

{

int i;

i=1;

while(i<=5)

{

    printf("%d \n", i);

    i++;

}

return 0;

}

29.   Write a C program to print the first ten odd numbers.

#include<stdio.h>

#include<conio.h>

int main()

{

int i, a;

i=1;

a=1;

while(i<=10)

{

    printf("%d \n", a);

    a=a+2;

    i++;

}

return 0;

}

30.   Write a C program to print the sum of digits of a given number.

#include<stdio.h>

#include<conio.h>

int main()

{

int n, s, r;

s=0;

printf("Enter any number: ");

scanf("%d", &n);

while(n>0)

{

    r=n%10;

    s=s+r;

    n=n/10;

}

printf("Sum of digits= %d",s);

return 0;

}

31.   WRITE A C PROGRAM  to display product of digits.

#include<stdio.h>

#include<conio.h>

int main()

{

int n, p, r;

p=1;

printf("Enter any number: ");

scanf("%d", &n);

while(n>0)

{

    r=n%10;

    p=p*r;

    n=n/10;

}

printf("Product of digits= %d",p);

return 0;

}

32.   WRITE A C PROGRAM  to reverse the given digits.

#include<stdio.h>

#include<conio.h>

int main()

{

int n, s, r;

s=0;

printf("Enter any number: ");

scanf("%d", &n);

while(n>0)

{

    r=n%10;

    s=s*10+r;

    n=n/10;

}

printf("Reverse digits= %d",s);

return 0;

}

33.   Write a C program to print the multiplication table of any input number up to tenth terms.

#include<stdio.h>

#include<conio.h>

int main()

{

int n, i=1, c=0;

printf("Enter any number: ");

scanf("%d", &n);

for(i=1;i<=10;i++)

{

  c=n*i;

  printf("%d X %d = %d \n", n,i,c);

}

return 0;

}

34.   WRITE A C PROGRAM  to check whether the given number is prime or not.

#include<stdio.h>

#include<conio.h>

int main()

{

int n, i=1, c=0;

printf("Enter any number: ");

scanf("%d", &n);

for(i=2;i<=n;i++)

{

   if(n%i==0)

    c=c+1;

}

if(c==2)

    printf("%d is prime number", n);

else

    printf("%d is not prime number", n);

return 0;

}

35.   WRITE A C PROGRAM  to check whether the given number is palindrome or not.

#include<stdio.h>

#include<conio.h>

int main()

{

int  n, s, r, a;

s=0;

printf("Enter any number: ");

scanf("%d", &n);

a=n;

while(n>0)

{

    r=n%10;

    s=s*10+r;

    n=n/10;

}

if(a==s)

{

    printf("%d is palindrome number", a);

}

else{

    printf("%d is not palindrome number",a);

}

return 0;

}

QBASIC File Handling Programming Solutions - SEE COMPUTER SCIENCE 2081

 


QBASIC File Handling Programming Solutions

 

1. Write a program to store Roll no., Name, Class and Address of any five students. [SEE 2074]

OPEN "Student.dat" FOR OUTPUT AS #1

FOR I = 1 TO 5
INPUT "Enter Roll No."; r
INPUT "Enter Name"; n$
INPUT "Enter Class"; c
INPUT "Enter Address"; a$
WRITE #1, r, n$, c, a$
NEXT I
CLOSE #1
END

 

2. A sequential data file called “student.dat” contains same records under the field’s name, english, nepali and computer. Write a program to add some more records in the same sequential data file. [SLC 2068]

OPEN “student.dat” FOR APPEND AS #1

DO

CLS

INPUT “ENTER NAME”; N$

INPUT “ENTER MARKS IN ENGLISH”; E

INPUT “ENTER MARKS IN NEPALI”; N

INPUT “ENTER MARKS IN COMPUTER”; C

WRITE #1, N$, E, N, C

INPUT “DO YOU WANT TO CONTINUE”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

3. A sequential data file “RECORD.DAT” and store Name, Address and Salary of employees of an office. WAP to add some more records in the data file “RECODR.DAT”. The program should terminate with user choice.

OPEN “RECORD.DAT” FOR APPEND AS #1

DO

CLS

INPUT “ENTER NAME”; N$

INPUT “ENTER MARKS IN ENGLISH”; E

INPUT “ENTER MARKS IN NEPALI”; N

INPUT “ENTER MARKS IN COMPUTER”; C

WRITE #1, N$, E, N, C

INPUT “DO YOU WANT TO CONTINUE”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

4. Create a data file to store the records of few employees having Name, Address, Post, Gender and Salary fields. [SEE 2073]

OPEN “std.rec” FOR OUTPUT AS #1

TOP:

CLS

INPUT “Enter Name”; N$

INPUT “Enter Address”; A$

INPUT “Enter Post”; P$

INPUT “Enter gender”; G$

INPUT “Enter Salary”; S

WRITE #1, N$, A$, P$, G$, S

INPUT “Do you want to continue”; CH$

IF UCASE$(CH$)=”Y” THEN GOTO TOP

CLOSE #1

END

5. Create a sequential data file ’Price.dat’ to store item name, quantity and Rate also calculate total amount(total=Quantity X Rate).Program should terminate according to the user’s choice. 

OPEN “price.dat” FOR OUTPUT AS #1

TOP:

CLS

INPUT “Enter Item Name”; N$

INPUT “Enter Quantity”; Q

INPUT “Enter Rate”; R

T = Q * R

WRITE #1, N$, Q, R, T

INPUT “Do you want to continue”; CH$

IF CH$=”Y” OR CH$ = “y” THEN GOTO TOP

CLOSE #1

END

 

6. Create a sequential data file’post.dat’ to store name and marks of any three subjects also calculate total and percentages only for 15 students.

OPEN "post.dat" FOR OUTPUT AS #1

FOR I = 1 TO 15
INPUT "Enter Name"; n$
INPUT "Enter marks in any three subjects”; A, B, C
T = A + B + C

P = T / 3

WRITE #1, n$, A, B, C, T, P

NEXT I
CLOSE #1
END

 

7. Store SIDNO, name, address and Telephone number of five students and display the records on monitor in sequential data file “STDINFO”

OPEN "STDINFO.DAT" FOR OUTPUT AS #1

FOR I = 1 TO 5

    CLS

    INPUT "ENTER NAME"; N$

    INPUT "ENTER ADDRESS"; A$

    INPUT "ENTER TELEPHONE"; T#

    WRITE #1, N$, A$, T#

NEXT I

CLOSE #1

OPEN "STDINFO.DAT" FOR INPUT AS #1

CLS

FOR I = 1 TO 5

    INPUT #1, N$, A$, T#

    PRINT N$, A$, T#

NEXT I

CLOSE #1

END

 

8. A sequential data file “Address.inf” contains serial no, name, address, telephone and email_id.WAP to record as many records as the user wants. The serial number should be generated automatically like 5001,5003,5005.

OPEN " Address.inf " FOR OUTPUT AS #1

DO

CLS

C = 5001

INPUT “ENTER NAME”; N$

INPUT “ENTER ADDRESS”; A$

INPUT “ENTER TELEPHONE”; T#

INPUT “ENTER EMAIL”; E$

    WRITE #1, C, N$, A$, T$, E$

C = C + 2

INPUT “DO YOU WANT TO CONTINUE (Y / N)”; CH$

LOOP WHILE UCASE$(CH$) = “Y”

CLOSE #1

END

 

9. A Sequential data file called "SEE.DAT" has stored data under the field heading Symbol No., Name, English, Nepali, and Computer. Write a program to display all the information of those students whose marks in Computer is more than 80.

OPEN "SEE.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

    INPUT #1, A, B$, C, D, E

    IF E > 80 THEN PRINT A, B$, C, D, E

WEND

CLOSE #1

END

 

10. A sequential data file “STD.TXT” contains name and marks in three different subjects of some students. Write a program to display only fail student’s records assuming pass marks 40.

OPEN "STD.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

    INPUT #1, B$, C, D, E

    IF C < 40 AND D <40 AND E <40 THEN PRINT B$, C, D, E

WEND

CLOSE #1

END

11.Write a program which reads records from the file ”Result.DAT” having the fields name, and marks of three different subjects and display only those records whose percentage is greater than 60 and less than 80. Also count the total number of records presenting in that data files.

OPEN "STD.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

    INPUT #1, B$, C, D, E

A=A+1

T=C+D+E

P=T/3

    IF P > 60 AND P < 80 THEN  PRINT B$, C, D, E

WEND

PRINT “TOTAL NO. OF RECORDS=”; A

CLOSE #1

END

 

12. Write a program to read all the records from the data file “STUDENT.TXT” and display all the records where the fields name are unknown.

OPEN "STUDENT.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

   LINE INPUT #1, A$

    PRINT A$

WEND

CLOSE #1

END

13. A data file "pabson.txt" contains the records composed of the fields like school, principal, address, contact. Write a program in Qbasic to display records of the schools located in either Kathmandu or Palpa

OPEN "PABSON.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C$, D

    IF UCASE$(C$) = “KATHMANDU” OR UCASE$(C$) = “PALPA” THEN PRINT A$, B$, C$, D

WEND

CLOSE #1

END

 

14. A data file “INFO.DAT” has numerous records in it with name, address age, and telephone numbers in it. Write a program to read all the records and print those with address “NEPAL” and age >15

OPEN "INFO.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C, D

    IF UCASE$(B$) = “NEPAL” AND C >15 THEN PRINT A$, B$, C, D

WEND

CLOSE #1

END

 

15. A sequential data file called 'ADDRESS.DAT' contains NAME, AGE, CITY and TELEPHONE fields. Write a program to display all the contents of that data file.

OPEN "ADDRESS.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B, C$, D

    PRINT A$, B, C$, D

WEND

CLOSE #1

END

 

16. A data file “lib.txt” consists of book’s name, author’s name and price of books. Write a program to count and display the total number of records present in the file.

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C

D = D + 1

WEND

PRINT “TOTAL NUMBER OF RECORDS=”; D

CLOSE #1

END

17. Write a program in QBASIC to open a sequential data file “EMP.DAT”, which contains employees records: Name, address and phone number and display all the records as well as total number of records stored in the file. 

OPEN "LIB.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, A$, B$, C

PRINT A$, B$, C

D = D + 1

WEND

PRINT “TOTAL NUMBER OF RECORDS=”; D

CLOSE #1

END

18. A sequential data file named “nabil.txt” contains record of clients of a bank including depositor’s name, deposited amount, time and rate of interest. Wap to display detail of all depositors including simple interest.

OPEN "NABIL.TXT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P, T, R

I=P*T*R/100

PRINT A$, B$, C, I

WEND

CLOSE #1

END

 

19. A sequential data file “SALARY.DAT” contains the information, Employee-Code, Employee-Name, Post, Basic-Salary. Write a program to display those records whose Basic-salary is between 10000 to 15000 and Post is ‘OFFICER’.

OPEN "SALARY.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, E,, N$, P$, S

    IF UCASE$(P$) = “OFFICER” AND S >= 10000 AND S>= 15000 THEN PRINT A$, B$, C, D

WEND

CLOSE #1

END

 

20. A data file name “EMP.DAT”, contains number of records having fields name, post and salary. Write a program to count total number of “Manager” in the data file. (hint: Manager is a post)

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

    IF UCASE$(P$) = “MANAGER” THEN PRINT C = C + 1

WEND

PRINT “TOTAL NO.OF MANAGERS ARE”; C

CLOSE #1

END

 

21. A sequential data file “emp.dat” contains name, post and salary fields of information about employees. Write a program to display all the information of employees along with tax amount (also tax is 15% of salary).

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

    T = 15 / 100 * S

PRINT N$, P$, S, T

WEND

CLOSE #1

END

22. A data file “Salary.Dat” contains the information of employee regarding their name, post and salary. Write a program to display all the information of employee whose salary is greater than 15000 and less than 40000.

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

    IF S >= 15000 AND S <= 40000 THEN PRINT N$, P$, S

WEND

CLOSE #1

END

23. Write a program that reads the ”INFO.DAT” file that has several record such as name, address, gender, post, and salary .The program display those record whose sex is male and salary more than 10,000 and also the program counts the total number of records in that file.

OPEN "INFO.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, A$, G$, P$, S

C = C + 1   

IF UCASE$(G$)=”M” AND S >= 10000 THEN PRINT N$, A$, G$, P$, S

WEND

PRINT “TOTAL NUMBER OF RECORDS=”; C

CLOSE #1

END

 

24. A sequential data file’post.dat’ has few records related to name, address, salary.WAP to display the records whose address begins with ‘S’ or ‘D’

OPEN "POST.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, P$, S

A$ = UCASE$(LEFT$(N$,1))   

IF A$ = “S” OR A$ = “D” THEN PRINT N$, P$, S

WEND

CLOSE #1

END

 

25. Write a program to open a data file “record.dat” that contains name, address, date of birth, email and telephone number of some employees. Now display all those records whose date of birth is in current month.

 

OPEN "birth.dat" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

    INPUT #1, n$, d$, a$

    b$ = LEFT$(DATE$, 2)

    c = VAL(b$)

    e$ = LEFT$(d$, 2)

    f = VAL(e$)

    IF c = f THEN PRINT n$, d$, a$

WEND

CLOSE #1

END

 

26. A sequential data file “Record.dat” has few records related to name, address, post and DOB(mm/dd/yyyy). WAP to display the records of all those who were born between 1971 to 1999.

 

OPEN "RECORD.dat" FOR INPUT AS #1

CLS

WHILE NOT EOF(1)

    INPUT #1, n$, a$, p$, d$

    d$ = RIGHT$(d$, 4)

    c = VAL(b$)

        IF c >= 1971 and c<=1999 THEN PRINT n$, d$, a$

WEND

CLOSE #1

END

 

27. Write a Qbasic program that read the "EMP.DAT" file with Name, Address, Post and Salary columns from E: drive that has 500 records of employees and displays only its last 50 records.

OPEN "E:\EMP.DAT" FOR INPUT AS #1

CLS

FOR i = 1 TO 500

    INPUT #1, n$, a$, p$, s

    IF i >= 450 AND i <= 500 THEN PRINT n$, a$, p$, s

NEXT i

CLOSE #1

END

 

28. A sequential data file has 100 records having field name, class and roll number. Write a program to display from 50th to 60th records.

 

OPEN "ABC.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, C, R

D = D + 1   

IF D >= 50 AND D <= 60 THEN PRINT N$, C, R

WEND

CLOSE #1

END

 

29. Write a program to display the first 10 records from a file named “resource.dat” having fields name, phone and email.

OPEN "RESOURCE.DAT" FOR INPUT AS #1

CLS

FOR I = 1 TO 10

  INPUT #1, N$, C, R

PRINT N$, C, R

NEXT I

CLOSE #1

END

30. A data file named “EMP.DAT” contains some records with the fields Code, Name, Post and Salary. Write a program to print odd position records of the data file.

OPEN "EMP.DAT" FOR INPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, C, N$, P$, S

D = D + 1   

IF MOD 2 = 1 THEN PRINT C, N$, P$, S

WEND

CLOSE #1

END

 

31. A sequential data file named “abc.dat” has several records having fields name, roll and class. Write a program to copy all the records of class 10 into a newly created file new.dat.

OPEN "ABC.DAT" FOR INPUT AS #1

OPEN "COPY.DAT" FOR OUTPUT AS #1

CLS

WHILE NOT EOF (1)

  INPUT #1, N$, R, C

IF C = 10 THEN WRITE #2, N$, R, C   

WEND

CLOSE #1, #2

END

32. A data file named “record.dat” contains name, age and salary for n number of persons. Write a program to input a name to search data from a data file. If the data is not found, then display the message “Data not found in the list”.

OPEN “RECORD.DAT” FOR INPUT AS #1

CLS

INPUT “Enter name to be searched”; S$

FLAG=0

WHILE NOT EOF(1)

INPUT #1, N$, A$, S

IF UCASE$(S$)=UCASE$(N$) THEN

PRINT N$, A$, S

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “Data not found”

CLOSE #1

END

33. A sequential data file 'Student.dat' contains registration number, student name, address and date of birth of some students. Write a program that asks a user to input a registration number and displays the record of the particular registration if present.

OPEN “STUDENT.DAT” FOR INPUT AS #1

CLS

INPUT “Enter registration no. to be searched”; S

FLAG=0

WHILE NOT EOF(1)

INPUT #1, R, N$, A$, D$

IF S = R THEN

PRINT R, N$, A$, D$

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “Data not found”

CLOSE #1

END

 

34. WAP that asks a post of the employee and displays his/her records from the sequential data file “XYZ.REC” having fields Name, Post, Dept and Salary.

OPEN “XYZ.REC” FOR INPUT AS #1

CLS

INPUT “Enter post to be searched”; S$

FLAG=0

WHILE NOT EOF(1)

INPUT #1, N$, P$, D$, S

IF UCASE$(S$)=UCASE$(P$) THEN

PRINT N$, P$, D$, S

FLAG=1

END IF

WEND

IF FLAG=0 THEN PRINT “Data not found”

CLOSE #1

END

 

 

 

 

 

35. Delete some records from “neps.dat” file where computer ask user to enter the record, which is to be deleted. (Fields are name, address, and telephone number)

 

OPEN “NEPS.DAT” FOR INPUT AS #1

OPEN “TEMP.DAT” FOR OUTPUT AS #1

CLS

INPUT “Enter name which is to be deleted”; D$

WHILE NOT EOF(1)

INPUT #1, N$, A$, T#

IF UCASE$(D$)<>UCASE$(N$) THEN

WRITE #2, N$, A$, T#

ELSE

PRINT “Deleted data=”; N$, A$, T#

END IF

WEND

CLOSE #1, #2

 KILL “NEPS.DAT”

NAME “TEMP.DAT” AS “NEPS.DAT”

END

 

36. A sequential data file “marks.dat” contains information such as student’s name, marks obtained in math, science and computer. Write a program that increase the marks of computer by 10 of those student who secured less than 40

OPEN "D:\PATIENT.DAT" FOR INPUT AS #1

OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2

CLS

WHILE NOT EOF(1)

    INPUT #1, N$, A, B, C

    IF C > 40 THEN

        WRITE #2, N$, A, B, C

    ELSE

        C = C + 10

        WRITE #2, N$, A, B, C

         END IF

WEND

CLOSE

KILL "D:\PATIENT.DAT"

NAME "D:\TEMP.DAT" AS "D:\PATIENT.DAT"

END

 

37. A sequential data file “RECORD.DAT” contains different records under fields: name rollno., name, address and percentage. Write a program to edit a record and display both edited and unedited records on the screen to compare them side by side.

OPEN "D:\RECORD" FOR INPUT AS #1
OPEN "d:\TEMP.DAT" FOR OUTPUT AS #2
CLS
INPUT "ENTER ROLL NUMBER TO EDIT DATA"; E
FLAG = 0
WHILE NOT EOF(1)
INPUT #1, R, N$, A$, P
IF E <> R THEN
WRITE #2, R, N$, A$, P
ELSE
INPUT "ENTER ROLL NUMBER"; ER
INPUT "ENTER NAME"; EN$
INPUT "ENTER ADDRESS"; EA$
INPUT "ENTER PERCENTAGE"; EP
WRITE #2, ER, EN$, EA$, EP
FLAG = 1
END IF
WEND
IF FLAG = 0 THEN
PRINT "DATA NOT FOUND"
ELSE
PRINT "NON EDITED DATA"
PRINT "ROLL NUMBER= "; R
PRINT "NAME= "; N$
PRINT "ADDRESS= "; A$
PRINT "PERCENTAGE= "; P
PRINT "---------------"
PRINT "EDITED DATA"
PRINT "ROLL NUMBER: "; ER
PRINT "NAME: "; EN$
PRINT "ADDRESS: "; EA$
PRINT "PERCENTAGE: "; EP
END IF
CLOSE
KILL "D:\SALARY.DAT"
NAME "D:\TEMP.DAT" AS "D:\SALARY.DAT"
END