All posts by jhaharsh92

About jhaharsh92

C++:- Harsh Bachelor of Technology Lovely Professional University

Pyramid pattern

<br /> 

#include<iostream>
using namespace std;
int main()
{
int i,j,k,l,a;
cout<<"Enter the number of lines in the pyramid=";
cin>>a;
cout<<endl;
for(i=1;i<=a;i++)
{
for(j=a;j>=i;j--)
cout<<" ";
for(k=1;k<=i;k++)
{
cout<<"*";
}
for(l=1;l<=i-1;l++)
cout<<"*";

cout<<endl;

}
return 0;
}

 

output:

capture

Computerized Crime Register:

<br />#include

#include
#include
#include
#include
#include using namespace std;
class project
{
public:
char crime[20];
char name[20];

void getdata()
{
cout << "\nEnter name= "; cin>>name;

cout << "Enter the crime= "; cin>>crime;
}

void showdata()
{
cout << "\nName= " << name << endl ;
cout << "crime= " << crime<<endl;
}
void writedata()
{
ofstream fout("crime.txt", ios::app | ios::out);
project obj;
obj.getdata();
fout.write((char*)&obj, sizeof(obj));
fout.close();
}
};
int main()
{
project obj;
int num, input, flag = 0;
char pname[20],pcrime[20];
lable:
system("cls");
cout << "1.Add data\n";
cout << "2.Search by name\n";
cout << "3.Search by crime\n";
cout << "4.See all data\n";
cout << "5.Exit\n";
cout << "Enter choice: "; cin >> input;
ifstream fin("crime.txt",ios::in);
switch(input)
{ //adding new data
case 1:
obj.writedata();
fin.close();
goto lable;
case 2: //searching by name
cout << "\nEnter name= "; cin>>pname;
while (fin.read((char*)&obj,sizeof(obj)))
if (strcmp(pname,obj.name)==0)
{
obj.showdata();
flag = 1;
}
fin.close();
if (flag == 0)
cout << "\n\nDATA NOT FOUND!!!";
getch();
goto lable;
case 3: //searching by crime
cout << "\nEnter crime= "; cin>>pcrime;
while (fin.read((char*)&obj, sizeof(obj)))
if (strcmp(pcrime,obj.crime)==0)
{
obj.showdata();
flag = 1;
}
fin.close();
if (flag == 0)
cout << "\n\nDATA NOT FOUND!!!";
getch();
goto lable;
case 4: //show the list of all data
cout << "\nList of data::\n";
while (fin.read((char*)&obj, sizeof(obj)))
{
obj.showdata();
cout << endl;
flag = 1;
}
fin.close();
if (flag == 0)
cout << "\n\nDATA NOT FOUND!!!";
getch();
goto lable;
case 5:
exit(0);
default:
goto lable;
}
}

output:

c1 c2 c3c4

Integer To English Word Converter :

<br />#include<iostream>
using namespace std;
int main()
{
int a,c,i=0;
int b[6];
cout<<"Enter the number=";
cin>>a;
if(a==0)
{
cout<<"Zero";
exit;
}
while(1)
{
b[i]=a%10;
a=a/10;
if(a==0)
{
break;
}
i++;
}
while(i>0)
{
if(i==5)
{
switch(b[i])
{
case 1:
{
cout<<"one lakh ";
i--;
break;
}
case 2:
{
cout<<"two lakh ";
i--;
break;
}
case 3:
{
cout<<"three lakh ";
i--;
break;
}
case 4:
{
cout<<"four lakh ";
i--;
break;
}
case 5:
{
cout<<"five lakh ";
i--;
break;
}
case 6:
{
cout<<"six lakh ";
i--;
break;
}
case 7:
{
cout<<"seven lakh ";
i--;
break;
}
case 8:
{
cout<<"eight lakh ";
i--;
break;
}
case 9:
{
cout<<"nine lakh ";
i--;
break;
}
default:
{
i--;
break;
}
}
}
if(i==4)
{
if(b[3]==0)
{
switch(b[4])
{
case 1:
{
cout<<"ten thousand ";
i--;
break;
}
case 2:
{
cout<<"twenty thousand ";
i--;
break;
}
case 3:
{
cout<<"thirty thousand ";
i--;
break;
}
case 4:
{
cout<<"forty thousand ";
i--;
break;
}
case 5:
{
cout<<"fifty thousand ";
i--;
break;
}
case 6:
{
cout<<"sixty thousand ";
i--;
break;
}
case 7:
{
cout<<"seven thhousand ";
i--;
break;
}
case 8:
{
cout<<"eight thousand ";
i--;
break;
}
case 9:
{
cout<<"ninty thousand ";
i--;
break;
}
default:
{
i--;
}
}
}
else
{
if(b[4]==1)
switch(b[3])
{
case 1:
{
cout<<"eleven thousand ";
i--;
i--;
break;
}
case 2:
{
cout<<"tweleve thousand ";
i--;
i--;
break;
}
case 3:
{
cout<<"thirteen thousand";
i--;
i--;
break;
}
case 4:
{
cout<<"fourteen thousand ";
i--;
i--;
break;
}
case 5:
{
cout<<"fifteen thousand ";
i--;
i--;
break;
}
case 6:
{
cout<<"sixteen thousand ";
i--;
i--;
break;
}
case 7:
{
cout<<"seventeen thousand ";
i--;
i--;
break;
}
case 8:
{
cout<<"eighteen thousand ";
i--;
i--;
break;
}
case 9:
{
cout<<"nineteen thousand ";
i--;
i--;
break;
}
default:
{
i--;
break;
}
}
else
{
switch(b[4])
{
case 2:
{
cout<<"twenty ";
i--;
break;
}
case 3:
{
cout<<"thirty ";
i--;
break;
}
case 4:
{
cout<<"forty ";
i--;
break;
}
case 5:
{
cout<<"fifty ";
i--;
break;
}
case 6:
{
cout<<"sixty ";
i--;
break;
}
case 7:
{
cout<<"seventy ";
i--;
break;
}
case 8:
{
cout<<"eighty ";
i--;
break;
}
case 9:
{
cout<<"ninty ";
i--;
break;
}
default:
{
i--;
break;
}
}
}
}
}
if(i==3)
{
switch(b[3])
{
case 1:
{
cout<<"one thousand ";
i--;
break;
}
case 2:
{
cout<<"two thousand ";
i--;
break;
}
case 3:
{
cout<<"three thousand ";
i--;
break;
}
case 4:
{
cout<<"four thousand ";
i--;
break;
}
case 5:
{
cout<<"five thousand ";
i--;
break;
}
case 6:
{
cout<<"six thousand ";
i--;
break;
}
case 7:
{
cout<<" seven thousand ";
i--;
break;
}
case 8:
{
cout<<"eight thousand ";
i--;
break;
}
case 9:
{
cout<<"nine thousand ";
i--;
break;
}
default:
{
i--;
break;
}
}
}
if(i==2)
{
switch(b[2])
{
case 1:
{
cout<<"one hundred ";
i--;
break;
}
case 2:
{
cout<<"two hundred ";
i--;
break;
}
case 3:
{
cout<<"three hundred ";
i--;
break;
}
case 4:
{
cout<<"four hundred ";
i--;
break;
}
case 5:
{
cout<<"five hundred ";
i--;
break;
}
case 6:
{
cout<<"six hundred ";
i--;
break;
}
case 7:
{
cout<<"seven hundred ";
i--;
break;
}
case 8:
{
cout<<"eight hundred ";
i--;
break;
}
case 9:
{
cout<<"nine hundred ";
i--;
break;
}
default:
{
i--;
break;
}
}
}
if(i==1)
{
if(1)
{
switch(b[1])
{
case 1:
{
if(b[0]==0)
{
cout<<"ten ";
i--;
}
break;
}
case 2:
{
cout<<"twenty ";
i--;
break;
}
case 3:
{
cout<<"thirty ";
i--;
break;
}
case 4:
{
cout<<"forty ";
i--;
break;
}
case 5:
{
cout<<"fifty ";
i--;
break;
}
case 6:
{
cout<<"sixty ";
i--;
break;
}
case 7:
{
cout<<"sevety ";
i--;
break;
}
case 8:
{
cout<<"eighty ";
i--;
break;
}
case 9:
{
cout<<"ninty ";
i--;
break;
}
default:
{
i--;
break;
}
}
}
if(b[1]==1)
{
switch(b[0])
{
case 1:
{
cout<<"eleven ";
i--;
break;
}
case 2:
{
cout<<"twelve ";
i--;
break;
}
case 3:
{
cout<<"thirteen ";
i--;
break;
}
case 4:
{
cout<<"forteen ";
i--;
break;
}
case 5:
{
cout<<"fifteen ";
i--;
break;
}
case 6:
{
cout<<"sixteen ";
i--;
break;
}
case 7:
{
cout<<"seventeen ";
i--;
break;
}
case 8:
{
cout<<"eighteen ";
i--;
break;
}
case 9:
{
cout<<"nineteen ";
i--;
break;
}
default:
{
i--;
break;
}
}
}
}
if(i==0&&b[1]!=1)
{
switch(b[0])
{
case 1:
{
cout<<"one";
i--;
break;
}
case 2:
{
cout<<"two";
i--;
break;
}
case 3:
{
cout<<"three";
i--;
break;
}
case 4:
{
cout<<"four";
i--;
break;
}
case 5:
{
cout<<"five";
i--;
break;
}
case 6:
{
cout<<"six";
i--;
break;
}
case 7:
{
cout<<"seven";
i--;
break;
}
case 8:
{
cout<<"eight";
i--;
break;
}
case 9:
{
cout<<"nine";
i--;
break;
}
default:
{
i--;
break;
}
}
}
else
{
i--;
break;
}
}
return 0;
}

output:-

capture
Output

Program that determines the number of trailing zeros at the end of X! (X factorial), where X is an arbitrary number.

<br />#include<iostream>
using namespace std;
int main()
{
long long a,b=1;
cout<<“Enter the number whose factorial you want to calculate=”;
cin>>a;
if(a==0)
{
cout<<endl<<“The factorial of the given number is=1″<<endl;
}
else
{

while(a>1)
{
b=b*a;
a–;
}

}
cout<<“The factorial of the given number is=”<<b<<endl;
a=0;
while(1)
{
if(b%10==0)
{
b=b/10;
a++;
}
else
{
break;
}
}
cout<<“The number of the trailing zeroes in the given factorial is=”<<a;
return 0;
}