0% found this document useful (0 votes)
4 views9 pages

Theory Assigment

Uploaded by

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

Theory Assigment

Uploaded by

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

Theory Assigment

Q1:Program to print a Half-Pyramid using Numbers.


Ans:-

#include <iostream>

using namespace std;

int main()

int rows;

cout << "Enter number of rows: ";

cin >> rows;

for(int i = 1; i <= rows; ++i)

for(int j = 1; j <= i; ++j)

cout << i << " ";

cout << "\n";

return 0;

}
Q2:Program to print a Half-Pyramid using Alphabets.
Ans:-
#include <iostream>

using namespace std;

int main()

char input,alphabet = 'A';

cout << "Enter the uppercase character you want to print in the last row: ";

cin >> input;

input = toupper(input);

for(int i = 1; i <= (input-'A'+1); ++i)

for(int j = 1; j <= i; ++j)

cout << alphabet << " ";

++alphabet;

cout << endl;


}

return 0; }

Q3: Program to print inverted Half-Pyramid using ”*”.


Ans:-
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = rows; i >= 1; --i) {
for(int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}
return 0;
}
Q4:Program to print a Full-Pyramid using ”*”.
Ans:-
#include <iostream>
using namespace std;
int main()
{
int space, rows;
cout <<"Enter number of rows: ";
cin >> rows;
for(int i = 1, k = 0; i <= rows; ++i, k = 0) {
for(space = 1; space <= rows-i; ++space) {
cout <<" ";
}
while(k != 2*i-1) {
cout << "* ";
++k;
}
cout << endl;
}
return 0;
}

Q5:Program to print Inverted Full-Pyramid using “*”.


Ans:-
#include <iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = rows; i >= 1; --i) {
for(int space = 0; space < rows-i; ++space)
cout << " ";
for(int j = i; j <= 2*i-1; ++j)
cout << "* ";
for(int j = 0; j < i-1; ++j)
cout << "* ";
cout << endl;
}
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;
}

You might also like