C++ Solution Full Paper-2
C++ Solution Full Paper-2
C++ Code:
#include <iostream>
void checkVowelOrConsonant(char c) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
}
int main() { char c; cout <<
c;
checkVowelOrConsonant(c);
return 0;
C++ Code:
#include <iostream>
endl;
return 0;
}
Problem 3: Check if an Input Character is an Alphabet, Digit, or Special Character C++ Code:
#include <iostream>
>> ch;
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
>= '0' && ch <= '9') cout << ch << " is a digit." <<
return 0;
C++ Code:
#include <iostream>
int main() {
switch (op) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
return 0;
C++ Code:
#include <iostream>
rows;
return 0;
}
#include <iostream>
// 6. Half-Pyramid Using *
void halfPyramid() {
void alphabetPyramid() {
char ch = 'A';
ch++;
void reverseHalfPyramid() {
void centeredPyramid() {
int rows = 5;
void numberPyramid() {
int num = 1;
void repeatedNumberPyramid() {
} }
int main() {
halfPyramid();
reverseHalfPyramid();
centeredPyramid();
numberPyramid();
repeatedNumberPyramid();
return 0;
#include <iostream>
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
int main() {
cout << "HCF/GCD of " << num1 << " and " << num2 << " is " << findHCF(num1, num2) <<
endl;
return 0;
#include <iostream>
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
return a;
int main() {
cout << "LCM of " << num1 << " and " << num2 << " is " << findLCM(num1, num2) <<
endl;
return 0;
#include <iostream>
num /= 10;
int main() {
int num;
if (isPalindrome(num))
else
return 0;
#include <iostream>
#include <cmath>
digits++;
num /= 10;
num = original;
num /= 10;
}
return sum == original;
int main() {
int num;
if (isArmstrong(num))
else
cout << num << " is not an Armstrong number." << endl;
return 0;
#include <iostream>
int main() {
int n;
cin >> n;
cout << "Sum of first " << n << " natural numbers is " << sum << endl;
return 0;
}
6. Program for Sum of Series 1-2+3-4...n
#include <iostream>
int sumSeries(int n) {
int sum = 0;
sum += (i % 2 == 0) ? -i : i;
return sum;
int main() {
int n;
cin >> n;
cout << "Sum of the series is " << sumSeries(n) << endl;
return 0;
}
*Question 1: Program to Compute the Sum of the First N Terms of the Series*
```
namespace std;
double calculate_series_sum(int n) {
double sum = 0;
return sum;
int main() {
int n;
cout << "Enter the number of terms: "; cin >> n; cout <<
0;
```
```
#include <iostream> using
namespace std;
int temp[100];
k++) { if (arr[i] ==
temp[k]) { found =
true; break;
if (!found) {
temp[j++] = arr[i];
i++) { arr[i] =
temp[i];
} n
= j; }
int main() {
int arr[100];
int n;
cout << "Enter the size of the array: "; cin
array: ";
return 0;
```
```
#include <iostream>
namespace std;
char c = tolower(text[i]);
if (c >= 'a' && c <= 'z') {
alphabet_counts[c - 'a']++;
for (int i = 0; i < 26; i++) { cout << (char)(i + 'a') << ": " <<
cin.getline(text, 100);
count_alphabets(text);
return 0;
```
```
#include <iostream>
namespace std;
cout << "Address of '" << string[i] << "': " << (void*)&string[i] << endl;
result;
```
namespace std;
result[k++] = arr1[i++];
} else { result[k++]
= arr2[j++];
while (i < m) {
result[k++] = arr1[i++];
while (j < n) {
result[k++] = arr2[j++];
delete[] result;
sizeof(arr2) / sizeof(arr2[0]);
return 0;
```
```
namespace std;
if (arr[mid] == key) {
return mid;
} else { cout << "Key found at index " << result <<
return 0;
```
```
- 1;
if (arr[mid] == key) {
= mid - 1; } else {
low = mid + 1;
return -1;
} else { cout << "Key found at index " << result <<
return 0;
```
```
namespace std;
if (b == 0) { return a;
int main() {
int num1, num2; cout << "Enter
```
#include <iostream>
#include <stdexcept>
class Matrix {
private: int
rows; int
cols; int**
data;
public:
data[i];
delete[] data;
data[row][col] = value;
return data[row][col];
}
Matrix* add(Matrix* other) { if (rows !=
return result;
>getElement(k, j);
result->setElement(i, j, sum);
return result;
}
Matrix* transpose() {
getElement(i, j));
return result;
};
int main() {
try {
1, 4);
1, 8);
delete mat1;
sum; delete
product; delete
transpose;
} catch
```
#include <iostream>
#include <string>
std::string name;
public:
virtual ~Person() {}
};
marks;
int year;
public:
Student(const std::string& name, const std::string& course, int marks, int year)
};
std::string department;
double salary;
public:
};
int main() {
person->display(); std::cout
<< std::endl;
delete person;
return 0;
```
```
#include <iostream>
#include <stdexcept>
double side1;
double side2;
double side3;
public:
if (side1 + side2 <= side3 || side2 + side3 <= side1 || side3 + side1 <= side2) {
throw std::invalid_argument("Sum of any two sides must be greater than the third
side");
side3;
- side3));
};
int main() {
try {
std::cout << "Area (Right Angled): " << triangle.calculateAreaRightAngled() << std::endl;
std::cout << "Area (Heron's Formula): " << triangle.calculateAreaHeron() << std::endl;
1;
return 0;
```
#include <iostream>
#include <fstream>
#include <string>
class Student { private:
int rollNo;
std::string name;
std::string className;
totalMarks;
public:
Student(int rollNo, const std::string& name, const std::string& className, int year, double
totalMarks)
rollNo << std::endl; std::cout << "Name: " << name <<
os << student.rollNo << " " << student.name << " " << student.className << " " <<
student.year << " " << student.totalMarks;
return os;
return is;
};
int main() {
Student students[] = {
};
std::ofstream fileOut("students.txt"); if
fileOut.close();
std::endl; return 1;
}
// Read Student objects from file and display
std::ifstream fileIn("students.txt"); if
fileIn.close();
std::endl; return 1;
return 0;
```
```
#include <iostream>
#include <fstream>
#include <string>
fileIn("input.txt");
std::ofstream
fileOut("output.txt");
if (fileIn.is_open() && fileOut.is_open()) {
if (!std::isspace(c)) { newline +=
c;
return 1;
return 0;
```