Theory Assigment
Theory Assigment
#include <iostream>
int main()
int rows;
return 0;
}
Q2:Program to print a Half-Pyramid using Alphabets.
Ans:-
#include <iostream>
int main()
cout << "Enter the uppercase character you want to print in the last row: ";
input = toupper(input);
++alphabet;
return 0; }
Test paper
SET-A
Q1: Write the output of the following code
int a = 1;
switch (a)
{
case 1:
cout <<"I am in case a \n";
case 2:
cout <<"I am in case b \n”;
break;
case 3:
cout<<"I am in case c \n";
default:
cout<<"I am in default \n";
}
Ans1: I am in case a
I am in case b
Q2: Identify the error in the code
int a= 10, b= 20, c;
a + b =c;
cout<< c;
Ans2: c=a+b
Q3: What are header files. Name any two header files you have used.
Ans3: Header files store predefined functions and their definitions. You can include them in
your code using the `#include` directive, which tells the compiler to process the header file
before compiling your program.
1) #include<iostream>
2) #include<iomainip>
Q4: What are the two types of programming methodology? Explain briefly.
Ans4: Object-oriented programming (OOP) centers on objects that represent real-world
entities. It involves storing data and behaviors within these objects and defining how they
interact to create a cohesive solution.
Functional programming breaks down a problem into self-sufficient functions, each
performing a specific task. These functions are combined to create a complete solution,
emphasizing immutability and avoiding side effects.
Q5: Explain the following operators: “<<”, “>>”
Ans5: “<<” this operator is used for print statement (like cout<<”a”).
“>>”this operator is used for input values (like cin<<”a”).
Q6: Define high level language and low-level languages
Ans6: High-level languages are user-friendly and easy for programmers to understand and
learn. In contrast, low-level languages are designed for machines, making them difficult for
humans to comprehend and learn. This creates a strong reliance on machines.
Q7: WAP to draw the following pattern
1
22
333
4444
55555
Ans7:
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
cout << i;
}
cout << endl;
}
return 0;
}
Q8: Explain the working of do-while loop with the help of a program
Ans8: The do-while loop evaluates its condition at the end, ensuring that the loop body
executes at least once, even if the condition is false. It is an exit-controlled loop.
#include <iostream>
using namespace std;
int main()
{
int i = 2;
do
{
cout << "Hello World\n";
i++;
}
while (i < 1); // test expression
return 0;
}