1.
a)write a c program to implement the matrix multiplication
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],mul[10][10],m,n,p,i,j,k;
printf("enter the no of rows:");
scanf("%d",&m);
printf("Enter the no of coloumns:");
scanf("%d",&n);
printf("Enter the elements for the first matrix:\n");
for(i=0;i<m;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);
}
}
printf("Enter the no of rows:");
scanf("%d",&n);
printf("Enter the number of coloumns:");
scanf("%d",&p);
printf("Enter the elements for the second matrix:\n");
for(i=0;i<n;i++){
for(j=0;j<p;j++){
scanf("%d",&b[i][j]);
}
}
printf("product of the matrix is:\n");
for(i=0;i<m;i++){
for(j=0;j<p;j++){
mul[i][j]=0;
for(k=0;k<n;k++){
mul[i][j]+=a[i][k]+b[k][j];
}
}
}
for(i=0;i<m;i++){
for(j=0;j<p;j++){
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}
1.b.)PRE INCREMENT AND PRE DECREMENT USING FRIEND FUNCTION
#include<iostream>
using namespace std;
class Number{
private:
int value;
public(int value) : value(val){}
friend Number& operator++(Number& num);
friend Number& operator--(Number& num);
void display() const{
std::cout<< "Value"<<value<<std::endl;
}
};
Number& operator++(Number& num){
++num.value;
return num;
}
Number& operator--(Number& num){
--num.value;
return num;
}
int main()
{
Number num(5);
std::cout<<"Orginal value:";
num.display;
num++;
std::cout<<"number after pre increment:";
num.display;
num--;
std::cout<<"Number after pre decrement:";
num.display;
return 0;
}
}
2.a)NET SALARAY AND GROSS SALARY:
#include <iostream>
class Employee {
private:
float basicPay;
int leavesTaken;
public:
Employee(float pay, int leaves) : basicPay(pay), leavesTaken(leaves) {}
float calculateHRA() const {
return 0.3 * basicPay * leavesTaken;
}
float calculateDA() const {
return 0.8 * basicPay;
}
float calculateGrossSalary() const {
return basicPay + calculateHRA() + calculateDA();
}
float calculateNetSalary() const {
int lossOfPay = (leavesTaken > 1) ? leavesTaken - 1 : 0;
float pfDeduction = 1800;
return calculateGrossSalary() - (lossOfPay * basicPay) - pfDeduction;
}
};
int main() {
float basicPay;
int leavesTaken;
// Get input from the user
std::cout << "Enter the basic pay: ";
std::cin >> basicPay;
std::cout << "Enter the number of leaves taken: ";
std::cin >> leavesTaken;
// Create an Employee object
Employee emp(basicPay, leavesTaken);
// Calculate gross and net salary
float grossSalary = emp.calculateGrossSalary();
float netSalary = emp.calculateNetSalary();
// Display the pay slip
std::cout << "------ Pay Slip ------" << std::endl;
std::cout << "Basic Pay: " << basicPay << std::endl;
std::cout << "Leaves Taken: " << leavesTaken << std::endl;
std::cout << "HRA: " << emp.calculateHRA() << std::endl;
std::cout << "DA: " << emp.calculateDA() << std::endl;
std::cout << "Gross Salary: " << grossSalary << std::endl;
std::cout << "Net Salary: " << netSalary << std::endl;
return 0;
}
2.b) write a code to print pattern:
1
12
123
1234
12345
#include<stdio.h>
int main()
{
int i,j,r=5;
for(i=1;i<=r;i++){
for(j=1;j<=i;j++){
printf("%d",j);
}
printf("\n");
}
return 0;
}
3)A) INTERNET SERVICE PROVIDER:
#include <iostream>
int main() {
const double packageAPrice = 9.95;
const double packageAHours = 10;
const double packageAExtraHourPrice = 2.00;
const double packageBPrice = 14.95;
const double packageBHours = 20;
const double packageBExtraHourPrice = 1.00;
const double packageCPrice = 19.95;
char package;
double hours;
std::cout << "Which package did you purchase (A, B, or C)? ";
std::cin >> package;
if (package != 'A' && package != 'B' && package != 'C') {
std::cout << "Invalid package selection. Please choose A, B, or C." << std::endl;
return 0;
}
std::cout << "How many hours did you use? ";
std::cin >> hours;
if (hours < 0 || hours > 744) {
std::cout << "Invalid number of hours. Please enter a value between 0 and 744." << std::endl;
return 0;
}
double totalAmountDue = 0;
if (package == 'A') {
totalAmountDue = packageAPrice;
if (hours > packageAHours) {
totalAmountDue += (hours - packageAHours) * packageAExtraHourPrice;
}
} else if (package == 'B') {
totalAmountDue = packageBPrice;
if (hours > packageBHours) {
totalAmountDue += (hours - packageBHours) * packageBExtraHourPrice;
}
} else {
totalAmountDue = packageCPrice;
}
std::cout << "Total amount due: Rs. " << totalAmountDue << std::endl;
return 0;
}
3.b)Write a c program to find the Fibonacci series using recursion.
#include<stdio.h>
Int Fibonacci(int n);
Int main(){
Int I,n;
Printf(“Enter the number of terms:”);
Scanf(“%d”,&n);
Printf(“Fibonacii series:”);
For(i=0;i<n;i++){
Printf(“%d”,Fibonacci(i));
}
Return 0;
}
Int fibonaci(int n){
If(n==0||n==1){
Return n;
}
Else{
Return Fibonacii(n-1)+(n-2);
}
Return 0;
}
4.a) write a program using class and objects to calculate the electricity bill
#include <iostream>
class ElectricityBill {
private:
double units;
public:
ElectricityBill(double units) {
this->units = units;
}
double calculateBill() {
double bill = 0;
if (units <= 130) {
bill = units * 3;
} else if (units <= 300) {
bill = 100 + (units - 150) * 3.75;
} else if (units <= 450) {
bill = 250 + (units - 350) * 4;
} else if (units <= 600) {
bill = 300 + (units - 450) * 4.25;
} else {
bill = 400 + (units - 600) * 3.75;
}
return bill;
}
};
int main() {
double units;
std::cout << "Enter the units of consumption: ";
std::cin >> units;
ElectricityBill consumer(units);
double totalBill = consumer.calculateBill();
std::cout << "Electricity Bill: Rs. " << totalBill << std::endl;
return 0;
}
4.b)Convert the m*n matrix to n*m matrix
#include<stdio.h>
int main(){
int i,j,r=3,c=3;
int a[r][c];
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d",&a[i][j]);
}
}
printf("The m*n matrix is:\n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\n");
printf("The n*m matrix is:\n");
for(j=0;j<c;j++){
for(i=0;i<r;i++){
printf("%d\t",a[i][j]);
}
printf("\n");
}
return 0;
}
5.a)booking tickets online
#include <iostream>
const double TICKET_PRICE = 100.0;
const double PARKING_FEE_PER_HOUR = 10.0;
const double CHILD_DISCOUNT = 0.0;
const double TEN_TO_FIFTEEN_DISCOUNT = 0.1;
const double FIFTEEN_TO_TWENTY_DISCOUNT = 0.05;
const double ABOVE_TWENTY_DISCOUNT = 0.0;
double calculateDiscount(double age);
int main() {
int numberOfPersons;
double totalAmountDue = 0.0;
double parkingFee = 0.0;
std::cout << "Enter the number of persons: ";
std::cin >> numberOfPersons;
for (int i = 1; i <= numberOfPersons; i++) {
double age;
std::cout << "Enter the age of person " << i << ": ";
std::cin >> age;
double discount = calculateDiscount(age);
double ticketAmount = TICKET_PRICE - (TICKET_PRICE * discount);
totalAmountDue += ticketAmount;
std::cout << "Enter the parking fee for person " << i << ": ";
std::cin >> parkingFee;
totalAmountDue += parkingFee;
std::cout << "Amount due after person " << i << "'s age: Rs. " << totalAmountDue << std::endl;
}
std::cout << "Total amount due for all persons: Rs. " << totalAmountDue << std::endl;
return 0;
}
double calculateDiscount(double age) {
if (age < 10) {
return CHILD_DISCOUNT;
} else if (age >= 10 && age <= 15) {
return TEN_TO_FIFTEEN_DISCOUNT;
} else if (age > 15 && age <= 20) {
return FIFTEEN_TO_TWENTY_DISCOUNT;
} else {
return ABOVE_TWENTY_DISCOUNT;
}
}
5.b)first letter of each string upper case
#include <iostream>
#include <string>
#include <cctype>
int main() {
std::string input;
std::cout << "Enter a string: ";
std::getline(std::cin, input);
bool isNewWord = true;
for (char& c : input) {
if (isNewWord && std::isalpha(c)) {
c = std::toupper(c);
isNewWord = false;
} else if (std::isspace(c)) {
isNewWord = true;
}
}
std::cout << "Output: " << input << std::endl;
return 0;
}
6)a) DEDUCTING TAX:
#include <iostream>
double calculateTax(double salary);
int main() {
double salary;
std::cout << "Enter the annual salary: ";
std::cin >> salary;
double tax = calculateTax(salary);
std::cout << "Tax deduction: " << tax << "%" << std::endl;
return 0;
}
double calculateTax(double salary) {
if (salary <= 180000) {
return 5.0;
} else if (salary <= 300000) {
return 7.0;
} else if (salary <= 500000) {
return 10.0;
} else if (salary <= 750000) {
return 12.0;
} else {
return 15.0;
}
}
6)b) write program to find SUMS OF DIGITS using recursion:
#include <iostream>
int sumOfDigits(int number);
int main() {
int number;
std::cout << "Enter a positive integer: ";
std::cin >> number;
int sum = sumOfDigits(number);
std::cout << "Sum of digits: " << sum << std::endl;
return 0;
}
int sumOfDigits(int number) {
if (number == 0) {
return 0;
}
return (number % 10) + sumOfDigits(number / 10);
}
7)a)write a c program to compute and display the banks service fee
#include <iostream>
class BankAccount {
private:
double balance;
int numChecks;
public:
BankAccount(double initialBalance, int checks) {
balance = initialBalance;
numChecks = checks;
}
double calculateFees() {
if (balance < 400.0) {
balance -= 15.0;
}
double checkFee;
if (numChecks < 20) {
checkFee = numChecks * 0.10;
} else if (numChecks >= 20 && numChecks <= 39) {
checkFee = numChecks * 0.08;
} else if (numChecks >= 40 && numChecks <= 59) {
checkFee = numChecks * 0.06;
} else {
checkFee = numChecks * 0.04;
}
return checkFee;
}
};
int main() {
double initialBalance;
int numChecks;
std::cout << "Enter the beginning balance: $";
std::cin >> initialBalance;
std::cout << "Enter the number of checks written: ";
std::cin >> numChecks;
BankAccount account(initialBalance, numChecks);
double fees = account.calculateFees();
std::cout << "Bank's service fees: $" << fees << std::endl;
return 0;
}
7)b)check whether any DIGIT APPEAR ONCE OR MORE:
#include <stdio.h>
#include <stdbool.h>
bool isDigitRepeated(int number);
int main() {
int number;
printf("Enter the Number: ");
scanf("%d", &number);
if (isDigitRepeated(number)) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
}
bool isDigitRepeated(int number) {
int digitCount[10] = {0};
if (number < 0) {
number = -number; // convert negative number to positive
}
while (number > 0) {
int digit = number % 10;
digitCount[digit]++;
number /= 10;
}
for (int i = 0; i < 10; i++) {
if (digitCount[i] > 1) {
return true;
}
}
return false;
}
8)a) DECIMAL TO BINARY CONVERTION:
#include <stdio.h>
void decimalToBinary();
int main() {
printf("Decimal to Binary Conversion\n");
decimalToBinary();
return 0;
}
void decimalToBinary() {
int decimal, binary[32], index = 0;
printf("Enter a decimal number: ");
scanf("%d", &decimal);
if (decimal == 0) {
printf("Binary: 0\n");
return;
}
while (decimal > 0) {
binary[index] = decimal % 2;
decimal /= 2;
index++;
}
printf("Binary: ");
for (int i = index - 1; i >= 0; i--) {
printf("%d", binary[i]);
}
printf("\n");
}
8)b) SWAP TWO NUMBERS using pass by value and reference
#include <iostream>
void swapByValue(int a, int b);
void swapByReference(int& a, int& b);
int main() {
int num1, num2;
std::cout << "Enter the first number: ";
std::cin >> num1;
std::cout << "Enter the second number: ";
std::cin >> num2;
// Swap by value
std::cout << "\nSwapping by value:\n";
std::cout << "Before swap: num1 = " << num1 << ", num2 = " << num2 << std::endl;
swapByValue(num1, num2);
std::cout << "After swap: num1 = " << num1 << ", num2 = " << num2 << std::endl;
// Swap by reference
std::cout << "\nSwapping by reference:\n";
std::cout << "Before swap: num1 = " << num1 << ", num2 = " << num2 << std::endl;
swapByReference(num1, num2);
std::cout << "After swap: num1 = " << num1 << ", num2 = " << num2 << std::endl;
return 0;
}
void swapByValue(int a, int b) {
int temp = a;
a = b;
b = temp;
}
void swapByReference(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
9)a) TIME CONVERTION
#include <iostream>
class Time {
private:
int hours;
int minutes;
int seconds;
public:
void setTime(int h, int m, int s) {
hours = h;
minutes = m;
seconds = s;
}
int getTimeInSeconds() {
return hours * 3600 + minutes * 60 + seconds;
}
void displayTime() {
int h = hours;
int m = minutes;
int s = seconds;
if (h < 10)
std::cout << "0";
std::cout << h << ":";
if (m < 10)
std::cout << "0";
std::cout << m << ":";
if (s < 10)
std::cout << "0";
std::cout << s << std::endl;
}
};
int main() {
Time time1, time2, result;
int h1, m1, s1;
int h2, m2, s2;
std::cout << "Enter the first time (hour:minute:second): ";
std::cin >> h1 >> m1 >> s1;
std::cout << "Enter the second time (hour:minute:second): ";
std::cin >> h2 >> m2 >> s2;
time1.setTime(h1, m1, s1);
time2.setTime(h2, m2, s2);
int totalSeconds = time1.getTimeInSeconds() + time2.getTimeInSeconds();
int h = totalSeconds / 3600;
int m = (totalSeconds % 3600) / 60;
int s = (totalSeconds % 3600) % 60;
result.setTime(h, m, s);
std::cout << "Result: ";
result.displayTime();
return 0;
}
9)b) SUM OF MIJOR AND MINOR diagonals elements in matrix:
#include <stdio.h>
#define SIZE 3
void sumDiagonals(int matrix[SIZE][SIZE]);
int main() {
int matrix[SIZE][SIZE];
int i, j;
printf("Enter the elements of the matrix:\n");
for (i = 0; i < SIZE; i++) {
for (j = 0; j < SIZE; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
sumDiagonals(matrix);
return 0;
}
void sumDiagonals(int matrix[SIZE][SIZE]) {
int i;
int majorDiagonalSum = 0;
int minorDiagonalSum = 0;
for (i = 0; i < SIZE; i++) {
majorDiagonalSum += matrix[i][i];
minorDiagonalSum += matrix[i][SIZE - 1 - i];
}
printf("Sum of major diagonal elements: %d\n", majorDiagonalSum);
printf("Sum of minor diagonal elements: %d\n", minorDiagonalSum);
}
10)A) write program to find SUMS OF DIGITS using recursion:
#include <iostream>
int sumOfDigits(int number);
int main() {
int number;
std::cout << "Enter a positive integer: ";
std::cin >> number;
int sum = sumOfDigits(number);
std::cout << "Sum of digits: " << sum << std::endl;
return 0;
}
int sumOfDigits(int number) {
if (number < 10)
return number;
else
return (number % 10) + sumOfDigits(number / 10);
}
10)B)check whether given is a TOEPLIX matrix
Write a C program to check whether the given matrix is Toeplix matrix
#include <stdio.h>
#include <stdbool.h>
#define SIZE 3
bool isToeplitz(int matrix[SIZE][SIZE]);
int main() {
int matrix[SIZE][SIZE];
int i, j;
printf("Enter the elements of the matrix:\n");
for (i = 0; i < SIZE; i++) {
for (j = 0; j < SIZE; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
bool result = isToeplitz(matrix);
if (result)
printf("The matrix is a Toeplitz matrix.\n");
else
printf("The matrix is not a Toeplitz matrix.\n");
return 0;
}
bool isToeplitz(int matrix[SIZE][SIZE]) {
int i, j;
// Check elements above the main diagonal
for (i = 0; i < SIZE - 1; i++) {
for (j = 0; j < SIZE - 1 - i; j++) {
if (matrix[i][j] != matrix[i + 1][j + 1])
return false;
}
}
// Check elements below the main diagonal
for (i = 1; i < SIZE - 1; i++) {
for (j = 0; j < SIZE - 1 - i; j++) {
if (matrix[i][j] != matrix[i + 1][j + 1])
return false;
}
}
return true;
}
11)A)VOLUME OF CUBE CYLINDER SPHERE
#include <iostream>
#include <cmath>
const double PI = 3.14159;
double calculateVolume(double side);
double calculateVolume(double radius, double height);
double calculateVolume(double radius);
int main() {
double side, radius, height;
// Cube
std::cout << "Enter the side length of the cube: ";
std::cin >> side;
double cubeVolume = calculateVolume(side);
std::cout << "Volume of the cube: " << cubeVolume << std::endl;
// Cylinder
std::cout << "Enter the radius of the cylinder: ";
std::cin >> radius;
std::cout << "Enter the height of the cylinder: ";
std::cin >> height;
double cylinderVolume = calculateVolume(radius, height);
std::cout << "Volume of the cylinder: " << cylinderVolume << std::endl;
// Sphere
std::cout << "Enter the radius of the sphere: ";
std::cin >> radius;
double sphereVolume = calculateVolume(radius);
std::cout << "Volume of the sphere: " << sphereVolume << std::endl;
return 0;
}
double calculateVolume(double side) {
return std::pow(side, 3);
}
double calculateVolume(double radius, double height) {
return PI * std::pow(radius, 2) * height;
}
double calculateVolume(double radius) {
return (4.0 / 3.0) * PI * std::pow(radius, 3);
}
11)B)to implement scalar matrix SCALAR MATRIX
#include <iostream>
#include <cmath>
const double PI = 3.14159;
double calculateVolume(double side);
double calculateVolume(double radius, double height);
double calculateVolume(double radius);
int main() {
double side, radius, height;
// Cube
std::cout << "Enter the side length of the cube: ";
std::cin >> side;
double cubeVolume = calculateVolume(side);
std::cout << "Volume of the cube: " << cubeVolume << std::endl;
// Cylinder
std::cout << "Enter the radius of the cylinder: ";
std::cin >> radius;
std::cout << "Enter the height of the cylinder: ";
std::cin >> height;
double cylinderVolume = calculateVolume(radius, height);
std::cout << "Volume of the cylinder: " << cylinderVolume << std::endl;
// Sphere
std::cout << "Enter the radius of the sphere: ";
std::cin >> radius;
double sphereVolume = calculateVolume(radius);
std::cout << "Volume of the sphere: " << sphereVolume << std::endl;
return 0;
}
double calculateVolume(double side) {
return std::pow(side, 3);
}
double calculateVolume(double radius, double height) {
return PI * std::pow(radius, 2) * height;
}
double calculateVolume(double radius) {
return (4.0 / 3.0) * PI * std::pow(radius, 3);
}
12)a) find the SQUARE ROOT OF THE GIVEN NUMBER:
#include <stdio.h>
#include <math.h>
double findSquareRoot(double number);
int main() {
double number, squareRoot;
printf("Enter a number: ");
scanf("%lf", &number);
squareRoot = findSquareRoot(number);
printf("Square root: %.2lf\n", squareRoot);
return 0;
}
double findSquareRoot(double number) {
return sqrt(number);
}
12)b) NOT FOUND SRY……..
13)A) ELECTRIC BILL;
#include <iostream>
#include <string>
using namespace std;
class User {
private:
string name;
int units;
public:
void getData() {
cout << "Enter name: ";
getline(cin >> ws, name);
cout << "Enter number of units consumed: ";
cin >> units;
}
float calculateCharges() {
float charges = 0;
if (units <= 100)
charges = units * 0.6;
else if (units <= 200)
charges = 60 + (units - 100) * 0.8;
else if (units <= 300)
charges = 120 + (units - 200) * 0.9;
else if (units <= 500)
charges = 180 + (units - 300) * 1;
else
charges = 380 + (units - 500) * 1.25;
if (charges > 250)
charges += charges * 0.15;
return charges;
}
void displayCharges() {
cout << "Name: " << name << endl;
cout << "Charges: Rs. " << calculateCharges() << endl;
}
};
int main() {
int numUsers;
cout << "Enter the number of users: ";
cin >> numUsers;
User* users = new User[numUsers];
for (int i = 0; i < numUsers; i++) {
cout << "User " << i + 1 << endl;
users[i].getData();
}
cout << endl << "Charges for users:" << endl;
for (int i = 0; i < numUsers; i++) {
users[i].displayCharges();
}
delete[] users;
return 0;
}
13)B)to arrange the set of numbers in ascending order
#include <stdio.h>
void bubbleSort(int arr[], int size);
void swap(int *a, int *b);
int main() {
int size, i;
printf("Enter the number of elements: ");
scanf("%d", &size);
int arr[size];
printf("Enter the elements:\n");
for (i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}
bubbleSort(arr, size);
printf("Array in ascending order:\n");
for (i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
void bubbleSort(int arr[], int size) {
int i, j;
for (i = 0; i < size - 1; i++) {
for (j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
swap(&arr[j], &arr[j + 1]);
}
}
}
}
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
14)a) write a program to read an arry of length 5 and print the position and value of the array
Elements less than 5.
#include <stdio.h>
int main() {
int arr[5];
int i;
printf("Input the 5 members of the array: ");
for (i = 0; i < 5; i++) {
scanf("%d", &arr[i]);
}
printf("Output: ");
for (i = 0; i < 5; i++) {
if (arr[i] < 5) {
printf("A[%d]-%d ", i, arr[i]);
}
}
printf("\n");
return 0;
}
14)b) write a c++ program using operator overloading in relational operator to compare two
numbers using operator <= and >=
#include <iostream>
using namespace std;
class Person {
private:
float weight;
float height;
public:
Person(float w, float h) {
weight = w;
height = h;
}
bool operator<(const Person& other) {
return calculateBMI() < other.calculateBMI();
}
float calculateBMI() const {
return weight / (height * height);
}
};
int main() {
float weight1, height1, weight2, height2;
cout << "Enter weight and height for Person 1: ";
cin >> weight1 >> height1;
cout << "Enter weight and height for Person 2: ";
cin >> weight2 >> height2;
Person person1(weight1, height1);
Person person2(weight2, height2);
if (person1 < person2) {
cout << "Person 1 has a lower BMI than Person 2" << endl;
} else if (person2 < person1) {
cout << "Person 2 has a lower BMI than Person 1" << endl;
} else {
cout << "Both Person 1 and Person 2 have the same BMI" << endl;
}
return 0;
}
15)a) BMI
#include <iostream>
using namespace std;
class Person {
private:
float weight;
float height;
public:
Person(float w, float h) {
weight = w;
height = h;
}
float calculateBMI() const {
return weight * 703 / (height * height);
}
void displayWeightCategory() const {
float bmi = calculateBMI();
cout << "BMI: " << bmi << endl;
if (bmi < 18.5) {
cout << "Underweight" << endl;
} else if (bmi <= 25) {
cout << "Optimal weight" << endl;
} else {
cout << "Overweight" << endl;
}
}
};
int main() {
float weight, height;
cout << "Enter weight (in pounds): ";
cin >> weight;
cout << "Enter height (in inches): ";
cin >> height;
Person person(weight, height);
person.displayWeightCategory();
return 0;
}
15)B) write a c++ program to generate possible substring from the given string
#include <iostream>
#include <string>
using namespace std;
void generateSubstrings(const string& str) {
int length = str.length();
for (int i = 0; i < length; i++) {
for (int j = 1; j <= length - i; j++) {
string substring = str.substr(i, j);
cout << substring << endl;
}
}
}
int main() {
string str;
cout << "Enter a string: ";
cin >> str;
cout << "Substrings: " << endl;
generateSubstrings(str);
return 0;