Program to find the number repeating maximum using classes

This is a program to find the number out of the given list of numbers which repeats the maximum no. of times.

We have predefined the numbers using array.

 

Code:

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int arr1[]={3,3,3,1,5,6,7};
    int arr2[7];
    int i,j,k=0,l=0;
    for(i=0;i<8;i++)
    {
        arr2[i-1]=k;
        k=0;

        for(j=0;j<8;j++)
        {
            if(arr1[i]==arr1[j])
            {
                k++;
            }

        }
    }
    for(i=0;i<7;i++)
    {
    cout<<arr1[i]<<" has repeated "<<arr2[i]<<" times."<<endl;
    }
    cout<<endl<<"The maximum repeats are shown below:"<<endl;

    for(i=0;i<8;i++)
    {
        if(l>1)
        {
            cout<<arr1[i-1]<<" has repeated "<<arr2[i-1]<<" times."<<endl;
            l=0;
        }
        for(j=0;j<8;j++)
        {
            if(arr2[i]>arr2[j])
            {
                l++;
            }
        }
    }
}

 

Program to create a saving account using class.

This is a basic c++ program to crate a saving account using class.

 

INPUT – time, rate of interest & balance

OUTPUT – Balance after that time.

Description:

We have to take the balance, rate of interest and time [in months] as input from user and display the balance which user will have after that time interval.

 

Code:

#include<iostream>
using namespace std;
class bank
{

 static float rate;;
    static float rate1;
    static float bal;
    int time;
    int amount;
    int case1;
public:
    void getdata();
    void display();
};
float bank::rate;
float bank::bal;
float bank::rate1;

int main()
{
    bank b1,b2;
    b1.getdata();
    b1.display();
}

void bank::getdata()
{
    cout<<"Enter your current balance"<<endl;
    cin>>bal;
    cout<<"Enter the time (in months) after which you want to deposit/withdraw."<<endl;
    cin>>time;
    cout<<"Enter the rate of interest"<<endl;
    cin>>rate;
    cout<<"Choose Operation"<<endl<<"1. Withdraw"<<endl<<"2. Deposit"<<endl;
    cin>>case1;
    cout<<"Enter the amount"<<endl;
    cin>>amount;

}

void bank::display()
{
    rate1=0.01*rate;
    switch(case1)
    {
    case 1:
    bal+=(bal*rate1*time)/12-amount;
    break;

    case 2:
        bal+=(bal*rate1*time)/12+amount;
        break;

    default:
        cout<<"Invalid option."<<endl;

    }
    cout<<"Your current balance is "<<bal;

}