0% found this document useful (0 votes)
5 views3 pages

Dcs 221 Las

The document provides a series of questions and answers related to programming concepts, specifically focusing on programming languages, C++ syntax, and basic programming constructs. It includes definitions of programming, translators, variables, operators, and looping mechanisms, along with sample C++ code for various tasks. Key topics covered include high-level programming languages, types of variables, and examples of C++ programs.

Uploaded by

abdulbasit.morai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Dcs 221 Las

The document provides a series of questions and answers related to programming concepts, specifically focusing on programming languages, C++ syntax, and basic programming constructs. It includes definitions of programming, translators, variables, operators, and looping mechanisms, along with sample C++ code for various tasks. Key topics covered include high-level programming languages, types of variables, and examples of C++ programs.

Uploaded by

abdulbasit.morai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Page 1 of 3

Dinlin dinlin DCS 221 PQ & A


Q1a. What do you understand by Programming? (5 marks
Answer
Programming refers to the act or process of writing set of unambiguous instructions (program) written
in any specific language ( e.g. C, C++, Java, Python) to perform a specific task.
It is mainly used to develop desktop applications, websites, and mobile applications.
b. List five (5) high level Programming Languages you know (5 marks,
Answer
i. c++ ii. Java iii. JavaScript iv. FORTRAN v. COBOL
Write a C++ program to print "Hello World, how are you doing 15 marks,
Answer
#include < iostream>
Using namespace std;
Int main () {
Sting x=”Hello World, how are you doing”;
Cout<< x ;
return 0;
}
Q2a. Briefly explain Translator, (4 marks,
Answer
a translator is a program that converts program written in programming languages to machine
executable codes.
b. State three (3) examples of translators you know. (6 marks,
1. compiler 2. Interpreter 3. Asssembler
2c. Differentiate between Compiler and interpreter(5 marks)
Answer
The difference is that the compiler translate all the source codes before execution, while the interpreter
translates line by line. They are all translators
Q3a. What is Variable in programming (4 marks)
Answer
In programming, Variables are containers for storing data values.
3b. List any four (4) types of variable you know in C++ programming Language (4 marka
Answer
1. int - stores integers (whole numbers), without decimals, such as 123 or -123
2. double - stores floating point numbers, with decimals, such as 19.99 or -19.99
3. char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
4. string - stores text, such as "Hello World". String values are surrounded by double quotes
5. bool - stores values with two states: true or false
3c. Write a C++ program that prints Difference between two numbers. 17 marks
Answer
#include < iostream>
Using namespace std;
Int main () {
int difference;
int x= 4
int y= 1
int difference = x-y

~still smart – that’s how we roll


Page 2 of 3

Cout<< “the difference is :” difference ;


return 0;
}
Q4a. What is Operator in programming? 13 marks
Operators are used to perform operations on variables and values
Answer
4b. List three (3) categories of operators we have in C++ programming language with examples of
operators in each category.
Answer
1. Arithmetic operators : examples are: addition, subtraction, division, multiplication, modulus, etc
2. Assignment operators: examples are: =, +=, -=, *=,
3. Comparison operators: eg: equal to(==), greater than(>), not equal to(!=), less than(<) etc.
4. Logical operators: eg, logical and(&&), logical or(||), logical not (!)
4c. Winite a C++ Program to print the largest number among three (3) numbers. marks
Answer
#include < iostream>
using namespace std;
int main () {
int n1, n2, n3 ;
cout << “enter three numbers: “;
cin >> n1 >> n2 >> n3;
if (n1 > n2 && n1 > n3) {
cout << “ to gaskiya “ << n1 << “ is the largest number” ;
} else if (n2 > n1 && n2 > n3) {
cout << n2 << “is the largest number” ;
} else {
cout << “ n3 is the largest number”
return 0;
}
}
Q5. State three (3) looping mechanisms you know in C++ program with their respective syntaxes
Answer
1. C++ While Loop: The while loop loops through a block of code as long as a specified condition is true
Syntax
While ( condition) {
// code block to be executed
}
2. C++ For Loop: When you know exactly how many times you want to loop through a block of code, use
the for loop instead of a while loop
Syntax
For ( statement 1; statement 2; statement 3) {
// code block to be executed
}
3. Do while loop: unlike while loop, this executes first before checking condition
Syntax
While ( condition) {
// code block to be executed
}

~still smart – that’s how we roll


Page 3 of 3

Q6. Write a C++ program to print your Name, Dept, Adm, Level and Gender (25marks
Answer
#include < iostream>
Using namespace std;
Int main () {
String = Name, Dept, Adm, Level, Gender;
Name = Zakariya Aminu;
Dept = computer;
Adm = Dcs 22072;
Level = 200l
Gender = male;
cout<< “Name :” << Name ;
cout<< “Department :” << Dept;
cout<< “Adm no :” << Adm ;
cout<< “Level :” << Level ;
cout<< “Gender :” << Gender ;
return 0;
}

~still smart – that’s how we roll

You might also like