UP Board Solutions for Class 10 Computer Science Revision Problem
UP Board Solutions for Class 10 Computer Science Revision Problem
Question 1.
Write about the different components of the computer.
Answer:
The three components of the computer are:
1. Computer Hardware: The electronic and mechanical components that make up a computer are called hardware. All computer systems contain four types of hardware components:
- Input Devices
- Output Devices
- Computer Processor
- Secondary Storage Devices.
2. Computer Software: Software is a series of instructions that tell the hardware how to perform tasks. Without software, hardware is useless. Hardware needs the instructions provided by the software to process data into information. Computer software can be divided into two parts Le., System software and Application software.
3. Computer User: The person who communicates with a computer or uses the information it generates is called a User.
Question 2.
Define different data types used in ‘C’ language. (UP 2011, 12, 19)
Answer:
Data Types in ‘C’ Language: In ‘C’ language, the foil- owing Data Types are used:
- Numeric data type
- Alphanumeric data type
- Date and time data type
- Logical data type.
1. Numeric data type: Numbers of any type constitute numeric data. The numeric data can contain only the numeric characters of 0 to 9, with or without the decimal point. Some important numeric data types are int, float and double types.
Type int: The data type, which stores numeric data, is one of the basic data types in any programming language. It contains a sequence of one or more digits. For example—int sum. The variable ‘sum’ can store an integer value. It stores non-fractional values and occupies 2 bytes.
Type float: The float data type can be used for storing values containing decimal places. The difference between int and float is only that the int type includes only whole numbers but the float type includes both whole as well as fractional numbers. It occupies 4 bytes.
Type double: The type double is used, when the accuracy obtained using the variable of the type float is not sufficient. Variables of the type double can store twice the number of digits as can a float type. It occupies 8 bytes. The type float saves memory as it takes only half as much space as a double.
2. Alphanumeric data type: This data type can be made up of any type of characters.
Numeric = 0 to 9
Alphabetic = A to Z and a to z
Special Characters = #, $, *, etc.
These types of characters are generally enclosed within quotes “122” is considered alphanumeric data. On alphanumeric data mathematical calculations cannot be performed.
For example:
Char can store a single character
e.g., char A = ‘X’ char A[5] = “HARSH”
A char type can also store a collection of characters known as a string.
3. Date and Time data type: These are special data types for date and time values.
Date: It is a single data type that handles both date and time values.
Time: It can handle date and time values separately.
4. Logical data type: Logical data can have only two values le., true and false. A single data type handles logical data. It is represented by Boolean data type.
Question 3.
WAP that reads an integer N and calculate its factorial. (UP 2004, 05)
Answer:
#include<stdio.h> #include<conio.h> main() { int n, i, fact = 1; printf (“Enter Non-Negative value \n”); scanf (“%d”, &n); for (i = 1; i <= n; i ++) { fact = fact * i; } printf (“factorial of %d = %d”, n, fact); }
Question 4.
Write a program in C language which can arrange ten numbers in ascending order. Print the output in a column. (UP 2007, 12, 19)
Or
Write a program in C language which will find out prime numbers between 1 and 100 and will print them in a column. (UP 2008)
Answer:
#include<stdio.h> #include<conio.h> void main () { int x [10]; int * i, sum = 0; printf (“ Enter 10 numeric values \n”); for (i = 0; i< = 10; i + +) { scanf (“% d \n”, & x [i]); sum = sum + x [1]; } printf (“sum of the elements is % d ”, sum); getch (); }
Question 5.
WAP to create a file in write mode and accept data from the user, and write it on file “student.txt.”
Answer:
Program:
#include<stdio.h> #include<conio.h> void main () { char ch; FILE *fp = fopen (“Student.txt”, “w”); clrscr (); if (fp = = NULL) { perror (“Error in opening file”); exit (1); } ch = getc (stdin); while (ch ! = ‘*’) { void main () { char ch; FILE *fp = fopen (“Student.txt”, “a”); clrscr ( ); if (fp = = NULL) }
Question 6.
Write a program to take the contents of a text file and copy them into another text file, character by character. (UP 2008, 16)
Answer:
Program:
#include<stdio.h> #include<conio.h> void main() { FILE * fsrc, *ftgt; char ch; clrscr(); fsrc = fopen(“tryl.c”,“r”); if (fs == NULL) . { puts (“Cannot open source file”) exit (); } ftgt = fopen (“try2.c”, “w”); if(ft == NULL) { puts (“Cannot open target file”); fclose(fs); exit(); } while(l) { ch = fgetc(fsrc); if (ch == EOF) break; else fputc(ch.ftgt); } fclose(fsrc); fclose(ftgt); }
Question 7.
What is a programming language? Write the classification of programming language. (UP 2010)
Or
Explain the following:
- Low-Level Language
- High-Level Language.
Or
What ‘Generation of programming language? Explain.(UP 2018)
Answer:
Programming Language: Language is a means of communication. Whenever we want to communicate with com- puter system, we need to do so using a language which is acceptable and understood by a computer. A language which is used to accomplish a task and write a solution to a given problem in the form of a program is known as the programming language.
A programming language has its own set of characters, terms, instructions, Commands, syntaxes and guidelines to use these commands. A program is always written following these rules and guidelines.
Classification of Programming Languages: Programming languages can be classified on the basis of generations of computers as follows:
This classification is according to the generic upgradations in the languages as per time. As time passed by, every language made significant improvements and showed some additional features.
Similar kinds of classification of programming languages can be written as following on the basis of characteristics and features of languages.
The above classification is in increasing order of developmental phases of languages too.
Low-Level Language: The languages that were used in the first-generation and early second generation are called as low-level languages. They directly used computer memories and other storage hardware like registers to write programs. These languages were highly hardware dependent or machine-dependent. Programs written for one kind of hardware platform cannot be used on some other machine. Low-level languages are further divided into the following two categories :
- Machine Language,
- Assembly Language.
1. Machine Language: As the name suggests, it used the data in writing programs which were directly understood by the computer. A computer can only accept and work on electronic signals. These electronic signals are actually a presence or absence of electronic current in a circuit. The presence of a pulse in a circuit is denoted by 1 and absence is symbolised by ‘O’. These are the only two digits which are used by a computer system and they are known as Binary digits (or abbreviated as Bits). A language that uses these two binary digits to write computer program is known as machine language.
A program written in machine language comprises instructions in the form of a series of 1’s and 0’s.
Machine language instruction is divided into two parts:
- Opcode,
- Operand (Address part).
OpCode: This is the first part of an instruction which tells to the computer, what is to be done or which operation is to be performed.
Operand: This is the second part of a machine language instruction which tells the address and location of data on which operation is to be performed.
2. Assembly Language: Assembly language was an advancement over machine language. It is considered as a low-level language of the second generation. In this language, binary representations for various types of data are replaced by some codes. These codes are known as ‘Mnemonics’. In assembly language, there are predefined mnemonics for an opcode, operands, registers (memory locations) etc. They collectively form an assembly language program.
High-Level Languages: Languages that were developed after machine language and assembly languages were put under the category of high-level languages.
Characteristics of High-Level Languages:
- High-level languages use simple English words and commonly used mathematical symbols. This feature of high-level language makes it easier for programmers to write programs in it.
- Programs written in high-level languages are highly readable simply by looking at a program. Any computer literate can understand the objective of the program. These languages provide better documentation facility in programs.
- High-level languages are procedure-oriented. It means that they concentrate more on procedures followed to solve any given problem.
- Debugging of programs written in high-level languages is much easier and fast as compared to assembly language.
- Programs written in high-level languages are machine-independent. It means that these programs can run on a wide variety of hardware platforms by making slight modifications if needed.
- High-level languages are translator based languages. This translator could either be an interpreter or a compiler.
Translator Based Languages: High-level languages can also be called as translator based languages. As explained earlier, the computer only understands machine language [le., language of 0’s and 1’s) and any other form of instruction given to it needs to be translated into machine language. High-level languages generally use simple English words and phrases which must be translated into its machine-level equivalents before execution. Therefore, for every high-level language, a separate translator is essential.
Translator: It is a kind of system software which converts a program written in high level language into machine language. This machine language code is actually executed by the computer to achieve results.
Translators can be divided into following two categories and accordingly languages are also classified as either :
- Interpreter based language
- Compiler based language.
1. Interpreter: It is a translator for high level languages. It translates every single instruction linewise and then executes it. This process continues until the end of the program. If it encounters any error, it is informed to the user immediately. Until an error is removed, the interpreter does not proceed in a forward direction. Thus, we can say that every single line of a program (also known as source program) is checked for errors, translated and executed sequentially. Basic is an interpreter based language.
2. Compiler: It is a translator for converting programs written in high level language into machine language. Its major function is the same as that of interpreter but it works differently. It scans the entire program and lists all errors at a time. Until or unless programmer rectifies all errors, program is not translated into machine code. On successful removal of all errors, object code is created. This object code is executed to obtain the desired result. The original program before the compilation process is called a source program.
Some compiler based languages are. ‘C\ C++, JAVA, COBOL, PASCAL, FORTRAN etc.
Fourth Generation Languages (4 GLs): These are a group of languages that made problem solving further easier than what was available in high level languages. High level languages are procedure-oriented languages, le., they focus more on the way of solving a problem. 4 GLs are a category of languages that focus more on the objective of the given problem than on the ways and means to solve it. These languages were designed in view of managing databases (Database is a collection of similar types of records).