Tcs 151251 Lab Manual

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Tcs 151251 Lab Manual as PDF for free.

More details

  • Words: 3,431
  • Pages: 25
COMAPUTER PROGRAMMING LAB. (ECS-151)

Department Of Computer Science & Engineering LIST OF EXPERIMENTS 1. To give the knowledge of basic DOS commands to the students & use of DOS editor. 2. To explain the difference between internal & external DOS commands and make 3. To give the basic knowledge of windows operating system to the student 4. To give the basic knowledge of notepad, WordPad, PowerPoint and Internet. 5. Implementation of ‘C’ program using the output and input functions. 6. Implementation of ‘C’ program using the console functions. 7. To implementation of c program using control statement. 8. To implementation of c program using switch statement. 9. To implementation of various gates using ‘C’ language. 10.

To implement the loops and the arithmetic operator

using ‘C’ 11.

To implement of arrays in ‘C’ language.

12.

To implement of matrices in ‘C’ language.

13.

To implement of strings in ‘C’ language.

1

COMAPUTER PROGRAMMING LAB. (ECS-151)

EXPERIMENT – 1

Objective: To give the knowledge of basic DOS commands to the students & use of DOS editor.

Theory & concepts: Basically the purpose of the operating system is to interact with user and control the various operations of the devices. Operating system is software, which gives control to the user to do the desired. In operating system category first you will Microsoft disk operating system. It is single user and single tasking operating system. DOS is command-based operating system. You just type the command and press the enter key then the command will execute. e.g. in question 1 some commands are given. For executing the command type the command on the command prompt and by pressing the enter key the command will execute. In question 1 for executing the DATE command, first type the date and press enter key, and the current date will be shown on screen. By DIR command user can see the directories present in the hard disk.

2

COMAPUTER PROGRAMMING LAB. (ECS-151)

In question 2 to form the following tree first make the directory by MD command. C:> MD RGEC (press Enter) Then by CD command change current directory to RGEC and again by MD command form new directory like this. Given tree can be seen by TREE command. In question 3 first make file by using Copy Con command. C:> Copy con abc.txt (press Enter) RGEC Meerut Ctrl+Z (press Enter) To make the modification in the file by using editor. C:> Edit abc.txt (press Enter) And then in editor change can be made. 1. Explain following commands dir, date, time, version, cls, type, edit, rd and commands. 2. Create the following tree with the help of md, cd, cd\, cd.. and tree commands. RGEC

CS IT ME EE EC

3

COMAPUTER PROGRAMMING LAB. (ECS-151)

3. Create a file “abc.txt” using copy con command and then make modifications in file using MS-DOS Editor.

EXPERIMENT – 2

Objective: To explain the difference between internal & external DOS commands and make simple batch programs. Theory & concepts: Internal commands are defined in the file command.com. As the system is boot the file is reside in main memory and these commands are the basic commands, which are necessary to run DOS. e.g. DIR, TYPE, MD, CLS, TIME External commands not require certain special DOS file for being executed. e.g. FORMAT, CHKDSK, XCOPY, ATTRIB, etc.

4

COMAPUTER PROGRAMMING LAB. (ECS-151)

In question 2 mention the type of command syntax and options like if we want to see te directories page wise use the switch p like that options should be shown. Batch file is just the collection of two or more DOS commands. Batch file is created as follows: • Open MS DOS prompt • Move the specified directory at which you want to create batch file. • Write two or more DOS commands, save and exit • Now for executing the batch file just type the name of file and by pressing enter key file will be executing. 1. Bring out the difference between external & internal commands. 2. Explain the use of following DOS commands, mentioning whether they are internal or external commands, syntax and available options. • • • • • • • • • • • • • • • • • • • • •

MD CD RD CLS DIR DATE TIME COPY CON TYPE TREE COPY DOSKEY PATH REM DEL CHKDSK FORMAT DISKCOPY MORE FDISK PROMPT

5

COMAPUTER PROGRAMMING LAB. (ECS-151)

• • • • •

SORT FIND ATTRIB XCOPY MEM

3.

What is batch file? How the batch file is created?

4.

Create a batch file that clears the screen and show

the date & time. 5.

Create a batch file that a. Show the directories b. Clear the screen c. Make the directory named RGEC d. Delete the directory RGEC

Without showing the commands to user

EXPERIMENT – 3 Objective: To give the basic knowledge of windows operating system to the student Theory and concepts: Windows is multi-user and multitasking operating system. It is the most popular operating system. It is the most popular operating

6

COMAPUTER PROGRAMMING LAB. (ECS-151)

system of the world. It based on GUI (Graphical User Interface). User can interact and work on this operating system easily. There are different versions of windows operating system is present like win 98, win 2000, win Xp etc. In second question different terms are given which is easily visualize to the user In third question display properties like resolution, background, screensaver, colors of bars etc. are adjusted. In fourth question basic operations like delete of directory or file. Deleting can be done by keyboard also by mouse. 1. Explain the features of windows operating system. 2. Define the terms: a) Desktop b) Taskbar c) Toolbar d) Windows Explorer e) Icons f) Buttons g) Scrollbar h) Menu bar 3. Define display properties? How it can be changed? 4. Define the term Drag And Drop? 5. How to perform these operations a) Copy b) Delete c) Make new file and directory d) Restore

7

COMAPUTER PROGRAMMING LAB. (ECS-151)

EXPERIMENT – 4 Objective: To give the basic knowledge of notepad, WordPad, PowerPoint and Internet. Theory and concept:As we know the OS is an system software. In which we can interact with hardware and do desired tasks but as the need arises, wee need different software to meet our objects. To fulfill different other software are used to perform particular thing are called application software. In this Experiment we interact with software like Ms-word, Ms-paint, Ms-PowerPoint, these are the application software used for the formatting of text, for making paintings, designing a seminar report etc. These software can be easily open by just clicking by the mouse. Question no. 4,5 and 6 is related to the Internet. Basically Internet is the vast network of the computers linked by cables and telephone lines. By Internet user can see the different websites. Search on a particular topic and also by using webcam users can see to each other. For doing such type of thing we need a software Microsoft Internet explorer by which we can open the sites. Many other browsing software is also available. 1. In MS-word, Note Pad, word pad Write application to principal for one-day leave. Write application to administrator for bonafide student certificate. 2. In paint Draw the map of India with state distribution (color). Map of UP with district distribution (color). 3. In Ms-PowerPoint Make a presentation on the topic role of computer in village Make a presentation on any topic of your choice. 4. Define the topic Internet Internet browser Search engine 5. Using google.com search engine, search jobs sites of India. 6. Make a E-mail account in rediffmail.com

8

COMAPUTER PROGRAMMING LAB. (ECS-151)

9

COMAPUTER PROGRAMMING LAB. (ECS-151)

EXPERIMENT – 5 Objective: To implementation of Unix commands. Theory & concepts: Unix is a multi-user and multitasking operating system. In this Experiment some commands are given are used to do some basic operations. Foe example to show the files and directories we use the ls command. For execution of commands simply type the command and press enter key. Explain the following UNIX commands. 1.

To show current path and directory

2.

To create a file by CAT command.

3.

To show the content of a file by CAT command.

4.

To copy one file in another file by CP command

5.

To show the directory by LS command.

6.

To move one file to another file by MV

command. 7.

To rename a file by MV command.

8.

To make a new directory by MKDIR command.

9.

To change the directory by CD command.

10.

To show the calendar of current year by CAL

command. 11.

To show system date by DATE command.

12.

To check how many users are working in

network by WHO command. 13.

To check our identity by WHO AM I command.

14.

To remove file by RM command.

15.

To remove directory by RMDIR command.

16.

To clear the screen by CLEAR command.

10

COMAPUTER PROGRAMMING LAB. (ECS-151)

17.

TO show the content of file as page wise by

MORE command. 18.

Sort the content of a file by SORT command.

19.

To calculate and solve some problems by BC

11

COMAPUTER PROGRAMMING LAB. (ECS-151)

Experiment –6 Objective- Implementation of ‘C’ program using the output and input functions. Theory and concepts: C is a general purpose programming language. Dennis Ritchie invents C. C is also called systemprogramming language because it is useful for writing compilers and operating systems. It has been used equally well to write the major programs in many different domains. C provides a variety of data types. The fundamental types are character and floating point of different size. In addition there is a hierarchy of derived data types created with the pointes, arrays, structure and union. In this Experiment user just declare the data type and by using input function (scanf) and output function (printf) can make the program. E.g To add two numbers. #include<stdio.h> main() { int a, b, sum; scanf(“%d %d ”, &a, &b); sum= a+b; printf(“%d”, sum); } Input a=3, b=4 Like this first header file stdio.h is included. Then by further program is written. Q-1) WAP to print the statement -: RGEC IS THE BEST INSTITUTE. Q-2) WAP to print the ODD, 12.00, 12.43, 12, c, a using the constants. Q-3) WAP to calculate to sum, division and multiplication of the two numbers. Q-4) WAP to swapping of the two numbers. Q-5) WAP to calculate the simple interest the values of rate of interest, time and amount is input by the user.

12

COMAPUTER PROGRAMMING LAB. (ECS-151)

Q-6) WAP to change the temperature into Fahrenheit to Celsius.

13

COMAPUTER PROGRAMMING LAB. (ECS-151)

EXPERIMENT – 7 Objective: To implementation of c program using control & switch statement. Concepts and theory:If-else (Control statement) The if else statement is used to express decisions. The syntax of ifelse is If (expression) Statement 1 else statement 2 In this else part is optional e.g. If we want to give condition that print the statement ‘Yes’ by input 1 and ‘No’ by input 0 then program will like that #include<stdio.h> main() { int a; scanf(“%d”,&a); if (a==1) printf(“Yes”); else printf(“No”); } Switch: Switch ststement is a multiway decisions that tests whethere an expression matches of a number of constant integer values and branches accordingly. e.g. switch (expression) { case const expr : ststement case const expr : ststement default : statements } /* Program to calculate final velocity, distance using Newton's Law*/ #include<stdio.h> #include void main() { int n;

14

COMAPUTER PROGRAMMING LAB. (ECS-151)

float u,v,a,t,s; clrscr(); printf("\n Enter three Newton's Laws of motion"); printf("\n 1. v=u+a*t \n 2. s=u*t+(1/2)*a*t*t \n 3. v*v=u*u+2*a*s"); printf("\n Enter Equation No. you want to use:"); scanf("%d",&n); switch(n) { case 1: printf("Enter the value of initial velocity(u), accelaration(a), and time(t)"); scanf("%f%f%f",&u,&a,&t); v=u+a*t; printf("\n The final velocity is v=%f",v); break; case 2: printf("Enter the value of initial velocity(u), accelaration(a), and time(t)"); scanf("%f%f%f",&u,&a,&t); s=u*t+(1/2)*a*t*t; printf("\n The distance travelled is s=%f",s); break; case 3: printf("Enter the value of initial velocity(u), accelaration(a), and distance travelled(s)"); scanf("%f%f%f",&u,&a,&s); v=sqrt((u*u)+(2*a*s)); printf("\n The final velocity is v=%f",v); default: printf("\n Wrong choice entered"); } getch(); } LoopsLoops are used to execute a particular ststement, instruction more than one time then loops are used. Loops are for, while , do while loop. for loopfor(initialize counter; test counter; increment counter) { do this;

15

COMAPUTER PROGRAMMING LAB. (ECS-151)

and this; and this; } e.g. to print any statement five times then loop will be like that for (i=0; i<=4; i++) { printf(“RGEC”); } PROGRAMS IN C USING CONTROL INSTRUCTIONS, LOOP SWITCH AND GOTO STATEMENTS 1. A grocery shop decides to give its customers a discount of 10% on the total expense if quantity purchased is more than 100. The quantity purchased and price per item is entered through the keyboard. WAP to calculate the final sales bill. #include<stdio.h> #include void main() { clrscr(); int qty; float rate,tot; float dis=0.0; printf("Enter quantity purchased and rate"); scanf("%d%f",&qty,&rate); if(qty>100) dis=0.1; tot=(qty*rate)-(qty*rate*dis); printf(" The total expense is %f",tot); getch(); }

2. The current year and the year of joining of any employee are taken as input from the keyboard. If the number of years of service is more than 3 then a bonus of Rs. 2500 is given else nothing else is done. The pay of an employee is calculated as under: If basic salary is less than Rs. 1500 then HRA-10% & DA90% of basic. If basic salary is greater than or equal to Rs. 1500 then HRA=Rs.500 & DA=98% of basic salary. #include<stdio.h> #include void main() {

16

COMAPUTER PROGRAMMING LAB. (ECS-151)

int cy,yoj,bs,yos,bonus; float da,hra,gs; clrscr(); printf("\n Enter current year and year of joining and basic salary"); scanf("%d%d%d",&cy,&yoj,&bs); yos=cy-yoj; if(yos>3) { bonus=2500; } else { bonus=0; } if(bs<1500) { da=(0.9)*bs; hra=(0.1)*bs; } else{ da=(0.98)*bs; hra=500.0; } gs=bs+da+hra+bonus; printf("\n Gross Salary is %f",gs); getch(); }

3. WAP to find the greatest of three numbers using if-else and conditional operators. /* Program to find Largest of three Numbers*/ #include<stdio.h> #include void main() { int a,b,c; clrscr(); printf("\n Enter three numbers"); scanf("%d%d%d",&a,&b,&c); if(a>b) { if(a>c) { printf("\n The Largest Number is %d",a); } else { printf("\n The largest number is %d",c); } } else { if(c>b) { printf("\n The largest number is %d",c);

17

COMAPUTER PROGRAMMING LAB. (ECS-151)

} else { printf("\n The largest number is %d",b); } } getch(); }

4. WAP to determine whether a given year is a leap year or not using && and || operators. /* Program to find whether a year is leap year or not*/ #include<stdio.h> #include void main() { int year; clrscr(); printf("\n Enter the year"); scanf("%d",&year); if(year%4==0) printf("\n The given year is leap year"); else printf("\n The given year is not an leap year"); getch(); }

5. Marks of 5 subjects are entered through the keyboard and division is allotted according to the following criteria: Greater than or equal to 60%I Division Between 50% and 59% II Division Between 40% and 49% III Division Less than 40% Fail #include<stdio.h> #include void main() { int m1,m2,m3,m4,m5,tot; float per; clrscr(); printf("\n Enter the marks of the student in five subjects:"); scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5); tot=m1+m2+m3+m4+m5; per=tot/5; if(per>=75) printf("\n The result is Honours"); else{ if(per>=60) printf("\n the result is First Division"); else{ if(per>=50 || per<60)

18

COMAPUTER PROGRAMMING LAB. (ECS-151)

printf("\n the result is Second Division"); else { if(per>=40 || per<50) printf("\n the result is Third Division"); else printf("\n the result is FAIL"); }} } getch(); } 6. A character is entered through the keyboard; find whether it is a capital letter, small letter or special symbol. The ASCII values are given below for reference A–Z a–z -0 – 9 Special symbols

65-90 97-122 48-57 0-47, 58-64, 91-96, 123-127

EXPERIMENT – 8 Objective:- To implementation of various gates using ‘C’ language. Theory & Concept:In this Experiment we will show the output of the gates using C programs. Gates can be easily implement by the control structure If-else and logical operator &&(AND) and ||(OR). e.g. For AND gate if (a==0 && b==0) printf(“Output is= 0””); else if (a>1 || b>1) printf(“Wrong no.”); else printf(“Output is= 1”); getch(); } 1. Write a program to get the output of AND gate. #include<stdio.h> #include

19

COMAPUTER PROGRAMMING LAB. (ECS-151)

void main() { int x,y; clrscr(); printf("\n Enter the inputs of the Gate"); scanf("%d%d",&x,&y); if(x==0 || y==0) printf("\n The output is 0"); else printf("\n The output is 1"); getch(); } 2. 3. 4. 5. 6. 7.

Write Write Write Write Write Write

a a a a a a

program program program program program program

to to to to to to

get the output of OR gate. get the output of NOR gate. get the output of X-OR gate. get the output of X-NOR gate. get the output of NAND gate. get the output of NOT gate. EXPERIMENT -9

Objective: To implement the loops and the arithmetic operator using ‘C’ Theory and concepts: Simply in this Experiment nesting of loops is done. How the loops are run to get the desired pattern or series? e.g In 1 program we want to print number between 1 to 100 than number is divisible by 2 or not. If divisible by 2 than number is even else it is odd. So program will be like as follows #include<stdio.h> main() { int i; for(i=1;i<=100;i++) { if(i%2==0) printf(“number is even”); else printf(“number is odd”); }

20

COMAPUTER PROGRAMMING LAB. (ECS-151)

Q-1) WAP to print the even number between 1 to 100 and also print how many numbers are even. #include<stdio.h> #include void main() { int i,a=0; clrscr(); for(i=1;i<=100;i++) { if(i%2==0) { printf("\t%d",i); a=a+1; }} printf("\n Total even numbers are=%d",a); getch(); } Q-2) WAP to find the factorial of the given number. #include<stdio.h> #include void main() { int i,n; int fact=1; clrscr(); printf("\n Enter the number whose factorial is required"); scanf("%d",&n); if(n==0) fact=1; else if(n==1) fact=1; else { for(i=1;i<=n;i++) { fact=fact*i; }} printf("\n The required factorial is %d",fact); getch(); }

21

COMAPUTER PROGRAMMING LAB. (ECS-151)

Q-3) WAP to check whether the given number is prime or composite. Q-4) WAP to find the sum of the digits of a number. #include<stdio.h> #include void main() { int sum=0,n,r; clrscr(); printf("\n Enter the number:"); scanf("%d",&n); while(n!=0) { r=n%10; n=n/10; sum=sum+r; } printf("\n The sum of digits are %d",sum); getch(); } Q-5) WAP to check whether the given number is palindrome or not. Q-6) WAP to print fibonacci series. Q-7) WAP (a) * * * *

to print given pattern(b) 1 * 1 * * 1 * * * 1

2 2 2

22

3 3

4

COMAPUTER PROGRAMMING LAB. (ECS-151)

#include<stdio.h> #include void main() { int i,j; clrscr(); for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { printf("\t *"); } printf("\n"); } getch(); }

#include<stdio.h> #include void main() { int i,j; clrscr(); for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { printf("\t%d",j); } printf("\n"); } getch(); }

23

COMAPUTER PROGRAMMING LAB. (ECS-151)

EXPERIMENT – 10 OBJECTIVE: - To implement of arrays, matrices and strings in ‘C’ language. THEORY AND CONCEPTS:- This Experiment is based on Arrays. An array is a collection of similar types of data items. Previously, we declared variable for taking and value but it can hold only one value at a time. Problem arises when we want to store the age of 80 employees or elements of any matrix. The concept array useful in this situation. The elements of array share the same variable name. The elements of arrays are indicated by specifying the array name followed by subscript in bracket. For example arr[10] declaration of arrayInt a[10]; For multidimensional array declaration is like that Int a[3][3]; It means 3 rows and 3 columns, 9 values can be stored in array a[3][3]. To store 5 values in arrays #include<stdio.h> main() { Int a[5],I; for (i=0 ; i<=4 ; i++) { scanf(“%d”,&a[i]); } for (i=0 ; i<=4 ; i++) { printf(“%d”, a[i]); } For e.g. #include<stdio.h> main() { char name[ ]=”RAM”; int i=0; while (i<=3) { printf(“%c”,name[i]); i++; }

24

COMAPUTER PROGRAMMING LAB. (ECS-151)

} It prints RAM. 1) WAP to store 10 numbers in array and then print them. 2) WAP to find out sum of all elements of an array. 3) WAP to find the largest and second largest in the given array. 4) WAP to transpose of the given matrix. 5) WAP to multiply of two matrices and print the result. 6) WAP to input a string and print it. 7) WAP to count the length of the string. String is input by the user. 8) WAP to count the numbers of vowels, consonants and spaces. 9) WAP to sort the string alphabetically. 10) WAP to check whether given string is palindrome or not.

25

Related Documents

Tcs 151251 Lab Manual
June 2020 0
Tcs
November 2019 32
Tcs
November 2019 32
Tcs
May 2020 18
Tcs
November 2019 29
Tcs
November 2019 36