Wednesday, 15 June 2016

A Program on Cafe billing.

C++ Code





#include<fstream>
#include<iostream>
using namespace std;
int starter ();
int continental ();
int chinese ();
int coffee ();
int desert ();
  
  


  int main ()

{
//***Variabel Declaration***//
int optp=1, item, bill=0,total=0;
 string  username ;
 string password ;

cout<<"Enter your admin details \n\nUser Name : ";
cin>>username;
cout<<"Password : ";
cin>>password;

if(username == "admin" ||  password=="*******")
{

while (optp!=6)
{
bill=bill+total;


cout<<"\n\n\nWelcome to Friends Cafe\n\n\n\t\t*********************MENU**********************\n\nCategories"; 
cout<<"\nPress:\n 1.     Starters\n 2.   Continental\n 3. Chinese\n 4. Coffee & Tea\n 5. Deserts\n 6. Exit \n\n" ;
cin>>optp;

if (optp==1  )
total=starter ();




if (optp==2)
  total=continental ();

if(optp==3)
total=chinese ();


if(optp==4)
total=coffee ();


if (optp==5)
total=desert ();

    
if (optp==6)
break;
else 
cout<<"Wrong Selection, Please select again\n";

}


//************asking details of customer*****************//
//if (bill!=0)
{



char name[100]={0};
string name1;
cout<<"\n\nKindly enter customer's Name & ID = ";
cin>>name1; 

//converting string into char array


for (int i=0 ; i<name1.length()  ; i++ )
{

name[i]=name1[i];

}
//********************************



//********Customer Matching from previous database**********//

int check=0,i=0;
char arr[100];
char  counter;

ifstream b;
b.open("imp_file",ios::in );

while(!b.eof())
{

b>>counter;

arr[i]=counter;

if (counter=='.')
{

for(int k=0; k<name1.length(); k++)
{

        if (arr[k]==name[k])

check=1;


else
{
check=0;
break;
}
}
i=-1;
}

if (check==1)
{
cout<<"\n-> Customer matches our database";
break;
}

i++;
}
b.close();
//******************************************


if (check==0)
{

//****Putting Customer data into file******
ofstream a;
a.open("imp_file",ios::app );
a<<name1<<".\n";
a.close();
//*****************************************
}


//*****Billing***********
float net =bill+ bill*0.16 ;
float discount= net - net*0.10;

if (check==1)
{
cout<<"\n\n\n\n\t\t\t-------------------------------\n\t\t\tYour bill is   "<<bill<<"\n\t\t\t16% GST included "<<bill*0.16;
cout<<"\n\t\t\t_______________________________\n\t\t\tTotal Bill = "<<net<<"\n\t\t\t10% Old Customer Discount "<<net*0.10<<"\n\t\t\t_______________________________";
cout<<"\n\t\t\tDiscounted bill is "<<discount<<"\n\n\t\t\t-------------------------------\n\n";
}
else
{

cout<<"\n\n\n\n\t\t\t------------------------\n\t\t\tYour bill is   "<<bill<<"\n\t\t\t16% GST included "<<bill*0.16;
cout<<"\n\t\t\t________________________\n\t\t\tTotal Bill = "<<net<<"\n\t\t\t________________________";
}

}

cout<<"\n\n\n                     \"THANKYOU FOR VISITING |FRIENDS CAFE|\"\n\n\n                       ";

}
else 
cout<<"\n incorrect password ";

return 0;
}







int starter (){

int item;
cout<<"\nPress:\n\n";
cout<<" 1.  Pineapple Juice       Rs-/120\n";
cout<<" 2.  Garlic Bread (4 pcs)  Rs-/250\n";
cout<<" 3.  Crunches              Rs-/100\n";
cout<<" 4.  Finger Fish           Rs-/150\n";
cin>>item;
if(item==1)
return 120;

if(item==2)
return 250;

if(item==3)
return 100;

if(item==4)
return 150;
        }

int continental ()
{
int item;
cout<<"\nPress:\n\n";
cout<<" 1.  Chicken Karahi          Rs-/300\n";
cout<<" 2.  Mutton Karahi           Rs-/600\n";
cout<<" 3.  Chicken Sajji           Rs-/550\n";
cout<<" 4.  Cheese Kabab            Rs-/400\n";
cin>>item;
if(item==1)
return 300;

if(item==2)
return 600;

if(item==3)
return 550;

if(item==4)
return 400;

        }


int chinese ()
{
int item;
cout<<"\nPress:\n\n";
cout<<" 1.  Chicken Manchurian           Rs-/700\n";
cout<<" 2.  Chicken Chouwmin             Rs-/550\n";
cout<<" 3.  Chicken Jalfrazi             Rs-/500\n";
cout<<" 4.  Pasta                        Rs-/350\n";
cin>>item;

if(item==1)
  return 700;

if(item==2)
return 550;

if(item==3)
return 500;

if(item==4)
return 350;


}



int coffee ()
{
int item;
cout<<"\nPress:\n\n";
cout<<" 1.  Coffee Latte               Rs-/250\n";
cout<<" 2.  Cappacinno                 Rs-/200\n";
cout<<" 3.  Espresso                   Rs-/300\n";
cout<<" 4.  Tea                        Rs-/120\n";
cin>>item;

if(item==1)
  return 250;

if(item==2)
return 200;

if(item==3)
return 300;

if(item==4)
return 120;


}
int desert ()
{
int item;
cout<<"/nPress:\n\n";
cout<<" 1.  Molten Lava    Rs-/270\n";
cout<<" 2.  Choco Pie      Rs-/130\n";
cout<<" 3.  Creamy Donut   Rs-/120\n";
cout<<" 4.  Tutti Frutti   Rs-/350\n";
cin>>item;
if(item==1)
return 270;

if(item==2)
return 130;

            if(item==3)
return 120;

if(item==4)
return 350;


}


Write a C++ Program to check Armstrong number.

C++ Code



#include<iostream>
using namespace std;
int main()
{
int num,s,d,n,rem=0;
        cout<<"Enter three digit num=";
cin>>num;
s=num;
    while (s!=0)
    {
    n=s%10;
    rem=rem+n*n*n;
    s=s/10;
}
if(rem==num)
{
cout<<"It is an armstrong number";
}
else
cout<<"It is not an armstrong number";
}

Fibonacci Series.

C++ Code



#include<iostream>
using namespace std;
int main()
{
int a=0,b=1,r,i,c;
cout<<"Enter range=";
cin>>r;

if (r>0)
{
cout<<a<<" "<<b<<" ";
}

    i=3;
    while (i<=r)
{
    c=a+b;
    cout<<c<<" ";
    a=b;
    b=c;
    i++;
}
}

Tuesday, 14 June 2016

Write a CLASS of a book. Which take values from the user and display the values.

#include<iostream>
using namespace std;
class book
{
public :
int id;
string title,aut;

void input()
{
cout<<"Enter id,title,author=";
cin>>id>>title>>aut;
}
void dis()
{
cout<<id<<endl<<title<<endl<<aut;
}
};
int main()
{
book b1,b2;
b1.input();
b2.input();


cout<<endl;
b1.dis();
cout<<endl;
b2.dis();



}

Write a class book. Declare the data members 1)Page 2)Price 3)Name. Take the data of two books and display all values of book whose price is greater.

#include<iostream> #include<string.h> using namespace std; class book { private: int page; string name; float price; public: book() { price=0.0; page=0; name=""; } book(int p,string n, float pr) { page=p; name= n; price=pr; }
void setpage(int p) { if(p>0) { page=p; } } void setname(string n) { if(n!="") { name=n; } }
void setprice(float pr) { if(pr>0.0) { price=pr; } } int getpage() { return page; } string getname() { return name; } float getprice() { return price; } void input() { cout<<"\nEnter How Many page of Book"<<endl; cin>>page; cout<<"Enter Book Name"<<endl; cin>>name; cout<<"Enter Book Price"<<endl; cin>>price; } void display(void) { cout<<"Book Page is"<<endl; cout<<page<<endl; cout<<"The Name is"<<endl; cout<<name<<endl; cout<<"The Price is"<<endl; cout<<price<<endl; } }; int main() { book b1,b2; cout<<"Enter book 1 data"; b1.input(); cout<<"Enter book 2 data"; b2.input(); cout<<"\nThe most Costly book is"<<endl; if(b1.getprice()>=b2.getprice()) { cout<<"Book 1"<<endl; cout<<b1.getprice(); cout<<"Rs"; } else { cout<<"Book 2"<<endl; cout<<b2.getprice(); cout<<"Rs"; } }
Add caption