program to find average of an array using pointer

/*Write a program that reads a group of numbers from the user
and places them in an array of type float.
Once the numbers are stored in the array,
the program should average them and print the result.
Use pointer notation wherever possible*/

/*
first of all we enter the num of elements and then user will enter elements value,and then calculate average using pointer*/

#include <iostream>
using namespace std;
class Avg
{
public:
int n,i;
float arr[50],sum=0,average;
void get()
{
cout<<"enter the number of elements:";
cin>>n;
cout<<"enter elements:\n";
for(i=0;i<n;i++)
{
cin>>arr[i];
}

}
void show()
{
for(i=0;i<n;i++)
{
sum+= arr[i];
}
average=sum/n;
cout<<"average of the above entered number is:"<<average;
}
};
int main()
{
Avg *obj;
obj->get();
obj->show();
return 0;
}
Output

c++ program for addition and multiplication of two matrices using classes and object using operator overloading

c++ program for addition and multiplication of  two matrices using classes and object using operator overloading:

addittion and multiplication of two matrixes involves for building a software wich can add or  multiply two matrices and give the result: program is given below


solution

#include <iostream>
using namespace std;
class function
{
public:
int a[10][10],i,j,n,m,k;

void input()
{
cout<<"enter order of matrix in m by n:";
cin>>m>>n;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
}
function operator +(function obj2)
{
function temp;
temp.n=n;
temp.m=m;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
temp.a[i][j]=a[i][j]+obj2.a[i][j];
}
}
return temp;
}
function operator *(function obj2)
{
function temp;
temp.n=n;
temp.m=m;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
temp.a[i][j]=0;
for(k=0;k<n;k++)
temp.a[i][j]+=a[i][k]*obj2.a[k][j];
}
return temp;
}
void show()
{
for(i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
}
};
int main()
{
function obj,obj2,result;
obj.input();
obj2.input();
result=obj+obj2;
cout<<"matrix 1 is:\n";
obj.show();
cout<<"matrix 2 is:\n";
obj2.show();
cout<<"sum of matrix :\n";
result.show();
result=obj*obj2;
cout<<"product of matrixes is:\n";
result.show();
return 0;
}

output:

Create a class account that stores customer name, account number and type of account.

Create a class account that stores customer name, account number and type of account. Fromthis derive the classes cur_acct and sav_acct to make them more specific to theirrequirements. Include necessary member functions in order to achieve the following tasks:a. Accept deposit from a customer and update the balance.b. Display the balance.c. Compute and deposit interest.d. Permit withdrawal and update the balance.e. Check for the minimum balance, impose penalty, necessary, and update the balance.


#include<iostream>
#include<math.h>
using namespace std;
class account
{
public:
char cust_name[50],type;
long acc_no,balance;
void get()
{
cout<<"\nenter customer name: ";
cin>>cust_name;
cout<<"enter account number:";
cin>>acc_no;
cout<<"enter types s for saving and c for current:";
cin>>type;
cout<<"enter balance:";
cin>>balance;
}
void display()
{
cout<<"\n Customer Name: "<<cust_name;
cout<<"\n Account Number: "<<acc_no;
cout<<"\n Type: "<<type;
cout<<"\n Balance: "<<balance;
}
void deposit()
{
int amt;
cout<<"\nenter the amount which you want to deposit:";
cin>>amt;
balance+=amt;
}
};
class sav_acct:public account
{
public:
int intr;
void comp_intrest()
{
int t1,r1=10;
intr=balance*pow(1+r1/12,t1);
cout<<intr;
balance+=intr;
}
void withdraw()
{
int amt;
cout<<"\nenter the amount which do you want to withdraw:";
cin>>amt;
if(balance>amt)
balance-=amt;
else
cout<<"\namount can't be withdrawn due to insufficient balance";
}
};
class curr_acct:public account
{
public:
void min_bal()
{
if(balance<500)
{
cout<<"\npenality imposed: \nnew balance is:"<<balance-50;
}
else
{
cout<<"\nno penalty imposed";
}
}
void withdraw()
{
int amt;
cout<<"\nenter amount to be withdrawn:";
cin>>amt;
if(amt>balance)
{
cout<<"amount can't be withdrawn due to insufficient balance";
}
else
{
balance-=amt;
}
}
};
int main()
{
sav_acct s1;
curr_acct c1;
c1.get();
c1.display();
c1.deposit();
c1.display();
c1.withdraw();
c1.display();
c1.min_bal();
s1.get();
s1.display();
s1.deposit();
s1.comp_intrest();
s1.display();
s1.withdraw();
s1.display();
}

output:



cpp progrom to check pallindrome of a string

cpp progrom to check entered string is pallindrome or not:

solution:

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string str;
cout<<"enter the string to check it is pallindrome or not:";
cin>>str;
int flag=0;
int l =str.size();
int i;
for(i=0;i<l;i++)
{
if(str[i]!=str[l-i-1])
flag =1;
}
if(flag==0)
{
cout<<"string is pallindrome";

}
else
{
cout<<"string is not pallindrome";
}
}

output:


program to check that string entered are anagram or not in cpp

program to check that string entered are anagram or not in cpp:

solution:

#include <iostream>
#include<string>
using namespace std;
int main() 
{
  char a[100],b[100];
  int flag=0;
  cout<<"enter ist string:";
  cin>>a;
  cout<<"enter 2nd string:";
  cin>>b;
  
    int first[26]={0},second[26]={0},i=0;
    while (a[i]!='\0')
    {
      first [a[i]-'a']++;
      i++;

    }
    i=0;
    while (b[i]!='\0')
    {
      second[b[i]-'a']++;
      i++;
    }
    for(i=0;i<26;i++)
    {
      if (first[i]!=second[i])
      {
       flag=1;
      }
    }

  if(flag==0)
  {
    cout<<"string entered are anagram";

  }
  else
  {
    cout<<"not anagram";
  }

}

Output:


why the value of 010 is 8 in cpp or any coding language;

why the value of 010 is 8 in cpp or any coding language;

#include<iostream>
using namespace std;
int main()
{
int x=010;
cout<<x;
}

Output:

0         1         0         basically means octal number so lets convert it into binary form

000    001      000     now combining it:

000001000               it basically represnt 1000 in binary which in decimal represent 8