20.3.21

Spring 2021 c++: hw-5

Create a OOP that counts the number of times a particular letter shows up in the word search. Count how many times it came in the string. Use Inheritance.

Examples

letterCounter([
  ["D", "E", "Y", "H", "A", "D"],
  ["C", "B", "Z", "Y", "J", "K"],
  ["D", "B", "C", "A", "M", "N"],
  ["F", "G", "G", "R", "S", "R"],
  ["V", "X", "H", "A", "S", "S"]
], "D") ➞ 3

// "D" shows up 3 times: twice in the first row, once in the third row.

letterCounter([
  ["D", "E", "Y", "H", "A", "D"],
  ["C", "B", "Z", "Y", "J", "K"],
  ["D", "B", "C", "A", "M", "N"],
  ["F", "G", "G", "R", "S", "R"],
  ["V", "X", "H", "A", "S", "S"]
], "H") ➞ 2

9.3.21

Spring 2021 C+: hw-4

Write a C++ program that will read an integer number (up to four digits) and convert it into words.

Sample Input/Output:


Spring 2021 c++ : hw-3

C++ OOP to display name and age


You have to read name and age of a person and display them on the output screen. Here, you will learn how to read string (name) with spaces in C++ language?

Here, you have to  declare a string (character array) variable named name that will store name of the person and integer variable named age that will store the age of the person.

Use Constructor, Destructor and Method in C++

Spring 2021 C++ : hw-2

1. Write a OOP to read string using cin function in c ++ . Count the number of character in that string without using built-in function.

2. Write a OOP to read a line of string using getline() function in c++. Count the number of word and number of character from that string. 

Spring 2021 C++ : hw-1

1.       The Farming Problem:

In this problem, a person is asking you to tell him how many legs can be counted among all his animals. The farmer has given three types sample:

A.)   Chicken: 2 legs

B.)    Cows: 4 legs

C.)    Goat : 4 legs

The farmer has counted his animals and he gives you a subtotal for each sample. You have to implement a function in OOP that returns the total number of legs of all the animals.

Rules: Don’t for get to return the result. Remember that the farmer wants to now the total number of legs and not the total number of animals.

Hints:

Farmer said that total number of animals is: 150

Farmer mentioned that there are 100 chickens, 25 cows and 25 goats

25.1.16

Index of C++ OOP Programming

C++ Program Structure -I

C++ Program Structure -II

C++ Variables, Identifiers and Data Types

Declaration of variables

Exercise Week-1: Variable, Datatype and Initialization

C++ : Object and Class with a traditional BOX example

C++ : Inheritance with BASE & DERIVED Classes 

Example: Salary Calculation using Inheritance in C++

C++ : Illustration of Overloading  in C++ with a example of real problem solution 

Example: Student Management System using Function Overloading using OOP in C++

C++ loadable and non-over loadable Operators

C++ : How Polymorphism works in C++ with implementation guideline


C++ : How Data Abstraction occurs in C++

C++ : Encapsulation with example in C++

C++ : Interfaces with real world problem solution in C++

Compound Data Types: Arrays in C++

Compound Data Types: Pointer in C++

Functions in C++ Programming Environment

OOP-Exercise : Classes and Objects with Constructor -cum- Destructor in C++

OOP-Exercise : Problems and Solutions on Encapsulation in C++

OOP-Exercise: Inheritance with problems and solutions in C++

OOP-Exercise-1 : Arithmetic Operators with operands as input

OOP-Exercise-2 : calculate square and cube of given number using inline function

OOP-Excercise-3 : Write a program to calculate simple interest using Function and also using Member variable/function in C++ OOP

OOP-Excercise-4.1 : Find the area of a triangle, area of a circle, and  area of rectangle using function overloading technique in C++

Function Programming : Excercise-4.2 : Check Whether the given number is Strange or Not.

OOP-Excercise-5 : Check Whether the given number is Strange or Not.

OOP-Excercise-6 : Write a Object Oriented Program to Display Student Information

OOP-Excercise-7 : Search an integer element from an Array of 10 values. Use Constructor and Destructor with Class in C++

OOP-Excercise-8 : Check whether the given number by user is palindrome or not palindrom. Use individual member function to take input, output and display. Use Inheritance in C++

OOP-Excercise-9 : Program to find area of triangle, circle, and rectangle using C++ Overloading

OOP-Excercise-10 : Check palindrome. Use Inheritance technique

Function-Excercise-11 : Recursive function to fill an Integer Array of 5 Elements

Function-Excercise-12 : Sum of all even elements from an Array

C++_Excercise-13 : Find ODD or EVEN

C++_Excercise-14 : Count the number of character

OOP-Excercise-15 : Banking System

OOP-Excercise-16 : Array Programming

C++_Excercise-17 : Function Programming

C++_Excercise-18 : Recursive Function Programming

C++ Definition gallery of object oriented programming

Inheritance in C++ to check a Perfect Number (C++_Excercise-19)

Constructor in c++ to Sum of all multipliers by given range

Inheritance in c++ to generate a Fibonacci series

Design a Payroll system using Single INHERITANCE in C++

Recursion in C++

Pay-Bill Calculation using OOP in C++

Write a C++ program using using inline function to find the largest of three integer numbers

Sort an array of integer in ascending order

Implement function overloading in C++

Create a 'DISTANCE' class

Create a class called 'EMPLOYEE'

Create a class called 'TIME'

Create a class 'COMPLEX' to hold a complex number

Create a 'MATRIX' class of size m X n

Derive a class ‘MAT’ from MATRIX class

illustrate multilevel inheritance

Illustrate multiple inheritance

Create a 'STRING' class which overloads ‘ = = ' operator

Write a C++ program to illustrate ‘this’ pointer

Create a base class called 'SHAPE'

C++ program to read a list

Design your own manipulator

C++ program that uses a single file

C++ program to read the file and output the list in the tabular format

Write an interactive, menu-driven program

Write a C++ program that displays the size

Define a function to find the minimum value contained in an array

Class template to represent a generic vector

Calculator using C++

simple interest using c++

array programming in c++

comparison operator in c++

conditional operator in c++

sum of all digits from an integer number using c++

find prime numbers and make sum of all primes using c++

find prime and check with the sum of all primes using c++

print strange number between 1 and 100000

print all integer which are divisible by 3 using c++

letter with loop c++

calculate total= 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 using c++

how to compare char in c++

switch statement in c++

how to find the smallest string in C++

switch statement in c++

Develop a Calculator using Constructor with Parameter in c++

Find the Area of Circle and Rectangle using Multilevel Inheritance in C++

Integer Array Search Using Constructor and Method in C++

Count the number of digit from an Integer Number given by user

Write a C++ program which will count digit from an integer number. The input(integer number) must be given by user from keyboard. This program will ask to the user for number of test to count the digit.

17.9.15

How to find the smallest string in C++

Write a function  min that has three C string parameters and returns the smallest.

Solution
char* min(char* a, char* b, char* c)
{
    return strcmp(a,b) < 0 ? strcmp(a,c) < 0 ? a : c : strcmp(b,c) < 0 ? b : c;
}

switch statement in c++

Question
In the Mapple Leaf School System, children are classified by age as follows:
less than 2, ineligible
2, toddler
3-5, early childhood
6-7, young reader
8-10, elementary
11 and 12, middle
13, impossible
14-16, high school
17-18, scholar
greater than 18, ineligible

Given an int variable  age , write a switch statement that prints out the appropriate label from the above list based on  age.

Solution
switch (age)
{
    case 0:
    case 1:
        cout << "ineligible";
        break;
    case 2:
        cout << "toddler";
        break;
    case 3:
    case 4:
    case 5:
        cout << "early childhood";
        break;
    case 6:
    case 7:
        cout << "young reader";
        break;
    case 8:
    case 9:
    case 10:
        cout << "elementary";
        break;
    case 11:
    case 12:
        cout << "middle";
        break;
    case 13:
        cout << "impossible";
        break;
case 14:
case 15:
case 16:
        cout << "high school";
        break;
case 17:
case 18:
        cout << "scholar";
        break;
default:
        cout << "ineligible";
        break;
}

how to compare char in c++

Assume that c is a char variable that has been declared and already given a value. Write an expression whose value is true if and only if c is NOT what is called a white space character (that is a space or a tab or a newline-- none of which result in ink being printed on paper).

Solution
(c==' ' || c=='\t' || c=='\n') ? false : true

calculate total= 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 using c++

Given an  int variable  n that has been initialized to a positive value and, in addition,  int variables  k and  total that have already been declared, use a  do...while loop to compute the sum of the cubes of the first  n whole numbers, and store this value in  total . Thus if  n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into  total . Use no variables other than  n ,  k , and  total .

Solution
total=0;
k=0;
do
{
    total+=k*k*k;
    k++;
}
while (k<=n);

letter with loop c++

Write a loop that displays all possible combinations of two letters where the letters are 'a', or 'b', or 'c', or 'd', or 'e'. The combinations should be displayed in ascending alphabetical order:

aa
ab
ac
ad
ae
ba
bb
...
ee

Solution:

for (char outerChar='a'; outerChar<='e'; outerChar++)
    for (char innerChar='a'; innerChar<='e'; innerChar++)
        cout << outerChar << innerChar << "\n";

15.9.15

print all integer which are divisible by 3 using c++

/* Series of Integer which is divide by 3 */

#include<iostream>
#include<conio.h>
using namespace std;
int series(int start,int last)
{
    cout<<"The series which is divide by 3 is:"<<endl;
    for(int i=start;i<=last;i++)
    {
        if(i%3==0)
        {
            cout<<i<<"\t";
        }
    }
}
int main()
{
    int start,last;
    cout<<"Enter start value:"<<endl;
    cin>>start;
    cout<<"Enter Last value:"<<endl;
    cin>>last;
    series(start,last);
    getch();
    return 0;
}

print strange number between 1 and 100000

/* print strange number 1-100000 */

#include<iostream>
#include<conio.h>
using namespace std;
int strange()
{
    int i,j,c,temp,rem,k;
    for(i=1;i<=100000;i++)
    {
        c=1;
        for(j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                c=0;
                break;
            }
        }
        if(c==1)
        {
            temp=i;
            while(temp>0)
            {
                rem=temp%10;
                k=1;
                for(j=2;j<=rem/2;j++)
                {
                    if(rem%j==0)
                    {
                        k=0;
                        break;
                    }
                }
                if((k==0)||(rem==0))
                {
                    k=0;
                    break;
                }
                rem/=10;
            }
            if(k==1)
            {
                cout<<i;
            }
        }
    }
    return 0;
}
int main()
{
    cout<<"The Strange number between 1 to 100000 is:"<<endl;
    strange();
    return 0;
}

find prime and check with the sum of all primes using c++

/* Print Prime List of the given range and do the sum then check weather the number is equal to the given number */

#include<iostream>
#include<conio.h>
using namespace std;
int prime_equal(int n)
{
    int c,sum=0;
    for(int i=1;i<=n;i++)
    {
        c=1;
        for(int j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                c=0;
                break;
            }
        }
        if(c==1)
        {
            cout<<i<<"\t";
            sum+=i;
        }
    }
    cout<<endl;
    cout<<"The sum is:"<<sum<<endl;
    if(sum==n)
    {
        cout<<"The sum is equal to "<<n<<endl;
    }
    else
    {
        cout<<"The sum is not equal to "<<n<<endl;
    }
 return 0;
}
int main()
{
    int n;
    cout<<"Enter Range:"<<endl;
    cin>>n;
    cout<<"prime List:"<<endl;
    prime_equal(n);
    return 0;
}

find prime numbers and make sum of all primes using c++

/* Find all primes and do the sum of those primes between a given range */

#include<iostream>
#include<conio.h>
using namespace std;
void prime_check(int first,int last)
{
    int c,j,count=0,sum=0;
    cout<<"The Number of Primes:"<<endl;
    for(int i=first;i<=last;i++)
    {
        c=1;
        for(j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                c=0;
                break;
            }
        }
        if(c==1)
        {
            count++;
            sum+=i;
        }
    }
        cout<<count<<"\t"<<endl;;
        cout<<"The sum of the prime number is:"<<sum<<endl;
}
int main()
{
    int first,last;
    cout<<"Range Start from:"<<endl;
    cin>>first;
    cout<<"End of Range:"<<endl;
    cin>>last;
    prime_check(first,last);
    getch();
    return 0; }

sum of all digits from an integer number using c++

/* A Program that reads a six digit integer and prints the sum of its six digit using Arithmatic operators. */

#include<iostream>
using namespace std;
int print_sum_of_digit(int number)
{
    int a,i,sum=0,count=0;
    if(number!=0)
    {
        while(number>0)
        {
            i=number%10;
            number=number/10;
            sum+=i;
            count++;
        }
         cout<<"Number of Digit:"<<count<<endl;
         return sum;
    }
}
int main()
{
    int number,i;
    cout<<"Enter the digit of six integer:"<<endl;
    cin>>number;
    cout<<"The sum of the digit is:"<<print_sum_of_digit(number)<<endl;
    return 0;
}

conditional operator in c++

/* Use of Conditional Operator */

#include<iostream>
using namespace std;
int Multiple(int a,int b);
int main()
{
int a,b;
cout<<"Enter two integer:"<<endl;
cin>>a>>b;
Multiple(a,b);
}
int Multiple(int a,int b)
{
if(a>b)
{
if(a%b==0)
cout<<"Multiple"<<endl;
else
cout<<"Not Multiple"<<endl;
}
else if(a<b)
{
if(b%a==0)
cout<<"Multiple"<<endl;
else
cout<<"Not Multiple"<<endl;
}
return 0;
}

comparison operator in c++

/* Use of Comparison Operator */

#include<iostream>
using namespace std;
string comparison(int age)
{
  string str;
  if(age<18)
    str="You are a child";
  else if(age>=18 && age<65)
    str="You are an adult";
  else if(age>=65)
    str="You are a senior citizen";
  return str;
}
int main()
{
    int age;
    cout<<"Enter Your Age to know who You are:"<<endl;
    cin>>age;
    cout<<comparison(age);
}

array programming in c++

/* Fill up an array,print the array,count number of values,count the number of odd,count the number of even,sum  of odd ,sum of even,average,find largest value,find smallest */

#include<iostream>
using namespace std;
int fill_up(int array[],int size);
int main()
{
    int array[10],size;
    cout<<"Enter the size of an array:"<<endl;
    cin>>size;
    fill_up(array,size);
}
int fill_up(int array[],int size)
{
    int count=0,even=0,odd=0,even_sum=0,odd_sum=0,largest,smallest;
    float avg=0.0,avg_sum=0.0;
    cout<<"Enter the element:"<<endl;
    for(int i=0;i<size;i++)
    {
        cin>>array[i];
        if(array[i]%2==0)
        {
           even++;
           even_sum+=array[i];
        }
        else
        {
            odd++;
            odd_sum+=array[i];
        }
        count++;
        avg_sum+=array[i];
    }
    avg=avg_sum/size;
    largest=array[0];
    smallest=array[0];
    for(int i=0;i<size;i++)
    {
        if(array[i]<smallest)
        {
            smallest=array[i];
        }
    }
    for(int i=0;i<size;i++)
    {
        if(array[i]>largest)
        {
            largest=array[i];
        }
    }
    cout<<"The value of the array is:"<<endl;
    for(int i=0;i<size;i++)
    {
        cout<<array[i]<<"\t";
    }
    cout<<endl;
    cout<<"The number of value into the array:"<<count<<endl;
    cout<<"The number of even Value is:"<<even<<endl;
    cout<<"The number of Odd value is:"<<odd<<endl;
    cout<<"The sum of the even number is:"<<even_sum<<endl;
    cout<<"The sum of the Odd number is:"<<odd_sum<<endl;
    cout<<"The Avarage is:"<<avg<<endl;
    cout<<"The Largest value is:"<<largest<<endl;
    cout<<"The Lowest value is:"<<smallest<<endl;
    return 0;
}