0% found this document useful (0 votes)
2 views

computer solved exercises Chapter11-13

The document covers JavaScript and C++ programming concepts, including syntax, variable declaration, and user input methods. It provides exercises on filling in blanks, writing code snippets, and defining programming terms. Additionally, it discusses the differences between programming languages, features of different generations of languages, and debugging techniques.

Uploaded by

feryalabid123456
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

computer solved exercises Chapter11-13

The document covers JavaScript and C++ programming concepts, including syntax, variable declaration, and user input methods. It provides exercises on filling in blanks, writing code snippets, and defining programming terms. Additionally, it discusses the differences between programming languages, features of different generations of languages, and debugging techniques.

Uploaded by

feryalabid123456
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Chapter # 11 JavaScript in HTML documents

Ex.A Fill in the blanks.

1. JavaScript
2. <SCRIPT>
3. window.write( )
4. window.prompt ( )
5. var

Ex.B write down the JavaScript statements to perform the following tasks.

 Declare three variables: length , breadth , area


Ans.
var length, breadth , area
 Accept the value of length and breadth in these variables from the user.
Ans.
length =prompt(“ enter length”);
breadth=prompt (“ enter breadth”);
area = prompt (“ enter area”);
 Convert the length and breadth into float type and store in in variable area.
Ans.
area= pasreFloat( length* breadth);
 Display the area with an appropriate message and in pink color.
Ans.
alert(“<font color=”pink“ > The area is :-, area </font> “);
 The command to proceed or to stop giving more input should come from
the user.
Ans.
var reply=confirm (“Do you want to continue”);
Ex.C Give the difference between the following.

Document.write() Window.prompt()
This method is used for displaying the This method is used for getting input
text on the browser window. from the user.
Window.alert() Window.confirm()
This method is used for displaying a This method evaluate a value, based on
short message to the user in a small a decision made by a user.
window.
HTML JavaScript
HTML is a markup language used to It is an scripting language used to add
create webpages. functionality to a web page.

parseInt() parseFloat()
This method converts string value into This method converts string value until
an integer value without decimal place first decimal place.
.
Arithmetic operators Comparison operators
Arithmetic operators are used to These operators are used to test if two
perform Arithmetic calculations using variables relate to each other in the
variables or constants. specified way. These return values
either True or False.

Ex.D Answer the following questions.

Q.1 Give three reasons why do you use JavaScript?

Ans.

 It helps to add interactive elements to HTML pages.


 Everyone can use JavaScript without purchasing a license.
 It is a scripting language which is light weighted programming language.
Q.2 What is an external JavaScript file? Give example.

Ans. An external JavaScript file is simply a text file containing JavaScript code with
a .js file extension.

<SCRIPT language= “JavaScript” src= “scriptFile.js”>

Q.3 What are the rules for writing a program in JavaScript?

Ans. Rules for writing a JavaScript program are:

1. The scripting language has to be written with in <SCRIPT> …</SCRIPT> tag


in HTML document.
2. The <SCRIPT> tag can either be written in <HEAD> or <BODY> of an HTML
document.
3. A program can have more than one <SCRIPT> …</SCRIPT> tags.
4. JavaScript is a case sensitive language.
5. Using semicolon at the end of the statement is optional.

Q.4 What should you do to make your program more readable?

Ans. Comments can be added to make the code more readable. Comments are
none executable statements. There are two different types of comments.

Single line comment: These comments begin with a double slash sign.

Multiple line comment: comment block is enclosed between /* and */.

Q.5 What are variables? Give example.

Ans. Variables are the names assigned to a memory location that can be used for
storing data. Its value can change during the execution of a script. We can declare
a variable in JavaScript by using var.

Example. var num1, num2, num3


Chapter # 13 Introduction to Programming concepts

Ex.A

1. Events
2. Rapid Application Development
3. Interpreter
4. Assembler
5. Machine

Ex.B Match the following.

1. Compiler -----------> C++


2. Interpreter ------------> BASIC
3. Fifth generation ----------> Artificial Intelligence
4. Fourth generation -------------> Access
5. Event-Driven Programming Language ---------------->Visual Basic

Ex. C Define the following terms.

1. Assembler
An assembler is a program which is used to convert assembly language
program into machine language.
2. Programming language
Programming language is used to write computer program that computer
can understand and interpret.
3. Modular programming
Modular programming refers to a technique in which the logical parts of a
problem is divided into a series of individual routines.
4. Event- driven programming
Programming the code that executes in response to an event is called
event-driven programming.
5. Object Oriented programming
In object oriented programming , a program is no longer a series of
instructions, but a collection of objects.
Ex.D Answer the following questions.
Q.1 what is a program?
Ans : A program is a set of instructions given to a computer to accomplish a
certain task.
Q.2 Name the five generations of computer language.
Ans. Five generations of computer language are:
First Generation (Machine Language)
Second Generation (Assembly language)
Third Generation (High Level Language)
Fourth Generation (Very high level languages)
Fifth Generation (Artificial Intelligence)

Q.3 Give two important features of first generation computer language.


Ans:
1. Instruction written in the form of 0s and 1s.
2. Binary codes can be easily interpreted by a computer.

Q.4 What are the important features of fourth generation computer language?

Ans.

1. Instructions are written in English like statements.


2. These are non-procedural.
3. Increase productivity.

Q.5 What is the basic difference between a compiler and an interpreter?

Compiler :

A compiler is a program that converts program written in high level into machine
language all at once.

Interpreter :

It is a program that translate source code into intermediate code line by line.
Chapter # 14 Introduction to C++

Ex.A Fill in the blanks.

1. Relational operators
2. Comments
3. Variables
4. Object program
5. Syntax error
6. Assignment

Ex.B Find the error and rewrite the correct code.

Original code Correct code


include<iostream.h> #include<iostream.h>
void main void main( )
{ {
cout>> “Code in C++!!”; cout<< “Code in C++ !! “;
} }

#include <iostream.h>
void main( ); #include<iostream.h>
{ void main( )
cin>> x; {
cout<< The value is>>x cin>>x;
} cout<<”The value is” << x;
}

Ex.C Classify as valid or invalid identifiers and give reason for your answer.

1. Num 1 :invalid because space is not allowed.


2. Contact no :invalid because space is not allowed.
3. FirstData :valid
4. First.LastName :invalid because period is not allowed.
5. 1Data :invalid because variable never begin with digit.
6. Num1/Num2 :invalid because space in not allowed.
Ex.D Write C++ statements for the following.

1. Declare a variable X to store 23.7.

Ans float X= 23.7;

2. Declare a variable Try to store “@”.

Ans. char Try= “@”;

3. Accept a number from the user in variable Num1.

Ans. cin>>Num1;

4. Declare a constant C to store value 34.

Ans. int C= 34;

5. Display the output of variable Alpha.

Ans. cout << Alpha;

Ex.E Give one word for the following.

1. Symbol to evaluate an expression.


Ans.Operators
2. To accept an input from the user.
Ans cin statement
3. Data type to store alphanumeric values.
Ans. char
4. Operator to assign a value to a variable.
Ans. Assignment operator
5. Reserved words for the language.
Ans. Keywords
Ex.F Answer the following questions.

Q.1 What is constant? Explain with the help of an example.

Ans. Identifiers whose value does not change during program execution are called
constants.

For example const float pi= 3.14;

const int age=26;

Q.2 What are the rules for naming an identifier?

Ans. The rules for naming identifiers are:

1. it can consist of alphabets, digits and only one special character that is an
underscore.
2. It can start with an alphabet or an underscore , but not with a digit.
3. C++ is a case sensitive.
4. The keywords cannot be used as identifiers.

Q.3 What is debugging?

Ans. Debugging is the process of identifying and removing errors from the
program. Press Alt+F9 to debug the program.

Q.4 What is variable initialization? Explain with the help of example.

Ans. Values in a variable can be either initilised or accepted from the user.
Variable initilisation is to assign a value to a variable that can change during the
execution of the program.

Example

int num1 = 23;

float marks=80.7;

char alpha= “A”;

Note: Copy solved examples of C++ programs (only page 171) in notebook .

You might also like