You are on page 1of 5

NAME : MUHAMMED ALEEM

TAHIR
ENROLLMENT : 01-134142-086
CLASS : BSCS-3D
Submitted to :DR. ARIF UR
RAHMAN

It works perfectly for any number from 0 to 99

This program gets a number from the user, divides it into two parts left side

and right side. The two numbers are passed through a function that convert

them into words.

UML OF CLASS:Alphabet

- num : int

+ setValue( n : int ) :
void
+ ConverValue( ) :
void
In this program used a header file which hold the class
Alphabet.

CODE >_
HEADER FILE ( header.h)

#ifndef HEADER_H
#define HEADER_H
using namespace std;
class Alphabet
{
private:

//headerfile defination

int num;
public:
void setValue(int n)
{
num=n;
}
void convertValue() //finction defination
{
int leftside,rightside;
string ones[] = {"
","one","two","three","four","five","six","seven","eight","nine","ten","eleven"
,"twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ni
neteen"};
string tens[] =
{"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"}; //
intilizing two arrays
if(num <= 0||num >= 99)
{
cout<<"Number is not between 0-99"<<endl;
}
else if(num >= 1 && num <= 19)
{
cout<<"Number you entered is : "<<ones[num]<<endl;
}
else if(num >=20 && num <= 99)
{
leftside = num / 10; // hold's the main logic
rightside = num % 10;
cout<<"\n\n\nNumber you entered is : "<<tens[leftside-2]<<"
"<<ones[rightside]<<endl;
}
}
};
#endif

MAIN .CPP FILE


#include<iostream>
#include<conio.h>
#include<string>

#include"header.h" // header file that we created


using namespace std;
int main()
{
Alphabet a;
int number;
cout<<"Enter number : ";
cin>>number;
a.setValue(number);
a.convertValue(); // calling the function
getch();
return 0;
}

OUT PUT :

You might also like