Pages

Thursday, September 17, 2015

UVA - 136 - Ugly Numbers Using Java

136 - Ugly Numbers

Ugly Numbers

Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence

1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...

shows the first 11 ugly numbers. By convention, 1 is included.

Write a program to find and print the 1500'th ugly number.

Input and Output

There is no input to this program. Output should consist of a single line as shown below, with <number> replaced by the number computed.

Sample output

The 1500'th ugly number is <number>.

public class Main{
 
    public static void main(String[] args) {
        System.out.println("The 1500'th ugly number is 859963392.");
 
    }
 
}

UVA-12577 (Hajj-e-Akbar) EASY Using Java

UVA-12577 (Hajj-e-Akbar) EASY

0001_thumb[6]

Capture_thumb[2]

 

import java.util.Scanner;
public class Main{
 
    public static void main(String[] args) {
        String a=new String();
        int i=1;
        Scanner s=new Scanner(System.in);
         while((a=s.nextLine()) != null)
            {
             if(a.charAt(0)=='*')
                   break;
             else if(a.equals("Hajj"))
             {
                 System.out.println("Case "+i+":"+" Hajj-e-Akbar");
             }
             else if (a.equals("Umrah")) {
                 System.out.println("Case "+i+":"+" Hajj-e-Asghar");
            }
             i++;
            }
 
    }
 
}

UVA-12478 - Hardest Problem Ever (Easy) Using Java

12478 - Hardest Problem Ever (Easy)
   1: public class Main{
   2:  
   3:     public static void main(String[] args) {
   4:         System.out.println("KABIR");
   5:  
   6:     }
   7:  
   8: }

UVA -11150–Cola (EASY) Using Java

11150 - Cola
Time limit: 3.000 seconds

Problem C : Cola

Time limit: 10 seconds

You see the following special offer by the convenience store:

" A bottle of Choco Cola for every 3 empty bottles returned "

Now you decide to buy some (say N) bottles of cola from the store. You would like to know how you can get the most cola from them.

The figure below shows the case where N = 8. Method 1 is the standard way: after finishing your 8 bottles of cola, you have 8 empty bottles. Take 6 of them and you get 2 new bottles of cola. Now after drinking them you have 4 empty bottles, so you take 3 of them to get yet another new cola. Finally, you have only 2 bottles in hand, so you cannot get new cola any more. Hence, you have enjoyed 8 + 2 + 1 = 11 bottles of cola.

You can actually do better! In Method 2, you first borrow an empty bottle from your friend (?! Or the storekeeper??), then you can enjoy 8 + 3 + 1 = 12 bottles of cola! Of course, you will have to return your remaining empty bottle back to your friend.

Capture

Input

Input consists of several lines, each containing an integer N (1 ≤ N ≤ 200).

Output

For each case, your program should output the maximum number of bottles of cola you can enjoy. You may borrow empty bottles from others, but if you do that, make sure that you have enough bottles afterwards to return to them.

Sample Input
8

Sample Output
12

Note: Drinking too much cola is bad for your health, so... don't try this at home!! :-)




Idea from a traditional IQ challenge question.
Special Thanks: Jonathan Mak

 



   1: import java.util.Scanner;
   2: public class Main{
   3:  
   4:     public static void main(String[] args) {
   5:         Scanner s=new Scanner(System.in);
   6:         int a,b,c,d,k=0;
   7:         
   8:         while(s.hasNext())
   9:         {
  10:             a=s.nextInt(); 
  11:             int sum=a;
  12:             a=a+1;
  13:         for(int i=1;i<a;a=k)
  14:         {
  15:             c=a/3;
  16:             d=a%3;
  17:             k=c+d;
  18:             sum=sum+c;
  19:             if(k==2||k==1)
  20:             {
  21:                 break;
  22:             }
  23:         }
  24:         System.out.println(sum);
  25:         }
  26:     }
  27:  
  28: }

Tuesday, May 5, 2015

File–Writing

File–Writing

 

 

main

 
public class writing2 {
    public static void main(String[] args) {
        writing obj=new writing();
        obj.openFile();
        obj.add();
        obj.close();
    }
}


import java.io.File;
import java.util.Formatter;
 
public class writing {
        private Formatter x;
        public void openFile()
        {
            try {
                x =new  Formatter("shadhi.txt");
            }
            catch(Exception e){
                System.out.println("you have an error");
            }
        }
        
        public void add()
        {
            x.format("%s%s%s","20"," new ","number");
        }
        public void close()
        {
            x.close();
        }
 
}

Tuesday, March 3, 2015

C Plus Plus Project : Quiz

Cpp Project: quiz  

 #include<iostream>  
 #include<stdlib.h>  
 #include<fstream>  
 using namespace std;  
 class contest  
 {  
 private:  
   char roll[10];  
   float x;  
   char name[20];  
   char s[100],ans;  
 public:  
   contest()  
   { x=0; };  
   void init();  
   void define();  
   void display();  
 };  
 void contest :: define()  
 {  
   ifstream in;  
   char a;  
    int i=1;  
   in.open("quiz.txt");  
   while(in.eof()==0)  
   {  
   in.getline(s,100);  
   cout<<endl<<s;  
   if(i==5)  
   {  
   in.get(a);  
   cout<<"\nans:";  
   cin>>ans;  
   i=-1;  
   if(ans==a)  
     {  
     x=x+5;  
     cout<<" *Your ans correct.\n";  
     }  
   else  
     {  
     if(x>0)  
     x=x-2.5;  
     cout<<" # Wrong ans.\n";  
     }  
   }  
   i++;  
   }  
   in.close();  
 }  
    void contest :: init()  
     {  
    cout<<"\t\t\t  Examinee Name:";  
    cin>>name;  
    cout<<"\t\t\t  Examinee roll:";  
    cin>>roll;  
     }  
    void contest :: display()  
     {  
    cout<<"\n **Result:\n";  
    cout<<"\t"<<name<<" you got total "<<x<<" marks,out of 25.\n";  
     }  
 int main()  
 {  
   contest r;  
   system("color F9");  
   cout<<"   \t\t\t~~~*** QUIZ CONTEST ***~~~\t   Total Marks:25\n\n";  
   r.init();  
   cout<<"\t*5 marks per Ques(half negative marking for wrong ans)";  
     L:  
   cout<<"\n\n\tselect your choice:\n"  
     <<"\n\t1 for start exam:"  
     <<"\n\t0 for quit the exam :";  
     int c;  
     cin>>c;  
     switch(c)  
     {  
     case 1:  
     r.define();  
     r.display();  
     break;  
     case 0:  
     exit(1);  
     default:  
     cout<<"invalid choice!";  
     goto L;  
     }  
 }  



Friday, February 20, 2015

C Plus Plus Project : CINEMA HALL TICKETING SYSTEM

Cpp Project: CINEMA HALL TICKETING SYSTEM  

 /*******************************************  
 CINEMA HALL TICKETING SYSTEM  
 *********************************************/  
 #include<iostream>  
 #include<string.h>  
 #include<stdio.h>  
 #include<fstream>  
 #include<stdlib.h>  
 using namespace std;  
 class plan  
 {  
   private:  
    int code;  
    int ticket,c,y,am;  
    float d,k,t;  
    char date[30],id[100];  
    char time[30];  
    int keep;  
    char z[30];  
    char h[30];  
   char ch;  
   public:  
    void get(void);  
    void display(void);  
    void i_delete(void);  
    void s(void);  
 };  
 void plan::get()  
 {  
     cout<<"Enter ID no:                  \n";  
     cin>>id;  
   X:  
   cout<<"Choose from the following movies\n";  
   cout<<"\n************************************************\n";  
   cout<<"*  1.The Avengers          \n";  
   cout<<"*  2.The Wolverine          \n";  
   cout<<"*  3.World War Z            \n";  
   cout<<"*  4.Fast and Furious 6           \n";  
   cout<<"*  5.The Amazing Spiderman           \n";  
   cout<<"\n************************************************\n";  
   cout<<"\nPlease,Enter your movie code(1-5):          \n";  
   cin>>code;  
   if(code<1 || code>5){  
   cout<<"\nInvalid input \n";  
  goto X;  
   }  
   O:  
   cout<<"\nEnter your ticket category \n1.regular  300 Taka(incl. 15% VAT)\n2.Premium  350 Taka(incl. 15% VAT)\n3.3D     400 Taka(incl. 15% VAT)\n";  
   cin>>ticket;  
   if(ticket<1 || ticket>3){  
   cout<<"\nInvalid input \n";  
  goto O;  
   }  
   cout<<"\nAmount:                  \n";  
   cin>>am;  
   switch(ticket)  
   {  
     case 1:  
     k=am*300.00+am*300.00*0.15;  
     break;  
     case 2:  
     k=am*350.00+am*350.00*0.15;  
     break;  
     case 3:  
     k=am*400.00+am*400.00*0.15;  
     break;  
   }  
   cout<<"\nEnter Date:(dd-m-yyyy) \n";  
   cin>>date;  
   cout<<"\nEnter Time:(hr.minam\pm) \n";  
   cin>>time;  
   FILE *fp;  
   fp=fopen("plan.txt","a");  
   fprintf(fp,"%s %d  %d \t %d   %0.2f  %s\t%s\n",id,code,ticket,am,k,date,time);  
   fclose(fp);  
 }  
 void plan::display()  
 {  
     cout<<"**********************************************************************\n";  
     cout<<"ID CODE TICKET AMOUNT TOTAL  DATE\t\tTIME"<<endl;  
     cout<<"**********************************************************************\n\n";  
     fstream fp;  
     fp.open("plan.txt",ios::in);  
     while(fp)  
     {  
     fp.get(ch);  
     cout<<ch;  
     }  
    }  
 void plan::i_delete()  
    {  
     FILE *fp;  
     int line_num = 1;  
     int search_result = 0;  
     char temp[5000];  
     char *e;  
     char del[100],m[5000];  
     int d,i,j=0,n=0,u=0;  
     printf("Enter your delete part\n");  
     scanf("%s",del);  
     e="plan.txt";  
     fp=fopen(e,"r");  
     while(fgets(temp, 5000, fp) != NULL)  
     {  
       if((strstr(temp, del)) != NULL)  
       {  
         u++;  
       }  
       else  
       {  
         for(i=0; temp[i]!='\0'; i++)  
         {  
           m[j]=temp[i];  
           j++;  
         }  
       }  
     }  
     fclose(fp);  
     fp=fopen(e,"w");  
     for(n=0; n<j; n++)  
     {  
       if(m[n]==1)  
       {  
         fprintf(fp,"\n");  
       }  
       else  
       {  
         fprintf(fp,"%c",m[n]);  
       }  
     }  
     cout<<"\nID has been successfully deleted from the list!\n";  
     if(u==0)  
       {  
         system("cls");  
         cout<<"\nSorry,there is no item like this to delete.\nTry again!\n";  
       }  
     fclose(fp);  
    }  
 void plan::s()  
 {  
     FILE *fp;  
      char search[100];  
     int m,n;  
     char temp[5000];  
     do  
     {  
       fp=fopen("plan.txt","r");  
       n=0;  
       printf("Enter the item name you want to search!\n");  
       scanf("%s",search);  
       system("cls");  
       while(fgets(temp, 5000,fp)!=NULL)  
       {  
         if(strstr(temp,search)!=NULL)  
         {  
           cout<<"Your search result:\n\n";  
           cout<<"**********************************************************************\n";  
           cout<<"ID CODE TICKET AMOUNT TOTAL  DATE\t\tTIME"<<endl;  
           cout<<"**********************************************************************\n\n";  
           printf("%s\n",temp);  
           n++;  
         }  
       }  
       if(n==0)  
       {  
         printf("\nSorry there is no item called '%s' in the list.\nTry again!\n\n",search);  
       }break;  
     }  
     while(m!=0);  
   }  
 int main()  
 {  
   plan p;  
   int m;  
   do  
   {  
     cout<<endl<<"****************************************************"<<endl;;  
     cout<<"\n\tWELCOME TO CINEMA HALL TICKETING SYSTEM\n";  
     cout<<endl<<"****************************************************"<<endl;  
     cout<<"\nEnter The Appropriate number.\n"  
     <<"\n1.For taking information."  
     <<"\n2.For display."  
     <<"\n3.For delete."  
     <<"\n4.For search."  
     <<"\n5.Quit."  
     <<"\nWhat is your option?\n ";  
   cin>>m;  
   switch(m)  
   {  
   case 1:  
      p.get();  
    break;  
   case 2:  
    cout<<"displaying info\n";  
     p.display();  
    break;  
    case 3:  
     p.i_delete();  
    break;  
   case 4:  
     p.s();  
    break;  
   case 5:  
    break;  
   default:  
    cout<<"\nError Input .Try Again.\n";  
   }  
 }while(m!=5);  
 return 0;  
 }  



C Plus Plus Project : Car Parking

Cpp Project: Car Parking  

 //Car Parking Management  
 #include <iostream> //c++ header file  
 #include <string.h> //character of array  
 #include <fstream> //using file  
 using namespace std;  
 ofstream outfile ("parking.txt", ios::out| ios::app);  
 ifstream infile ("parking.txt", ios::in);  
 //----------------------------------------------------------------------------  
 //-----------------------------Driver Class-----------------------------------  
 class Driver  
 {  
 private:  
   char name[20];  
 public:  
   Driver();  
   Driver(char nam[20]);  
   void input_data();  
   void input_data(char nam[]);  
   void show_data();  
   char* get_name();  
   void write_file();  
 };  
 Driver::Driver()  
 {  
 }  
 Driver::Driver(char nam[])  
 {  
   strcpy(name,nam);  
 }  
 void Driver::input_data(char nam[])  
 {  
   strcpy(name,nam);  
 }  
 void Driver::input_data()  
 {  
   cout << "\n\tEnter Driver Name   : ";  
   char gr=getchar();  
   gets(name);  
 }  
 void Driver::show_data()  
 {  
   cout << "\n\tDriver Name    : " << name;  
 }  
 char* Driver::get_name()  
 {  
   return name;  
 }  
 void Driver::write_file()  
 {  
   outfile << "\n\tDriver Name    : " << name;  
 }  
 //-----------------------------------------------------------------------------  
 //--------------------------------Car class------------------------------------  
 class Car  
 {  
 private:  
   char id[20];  
   char type;  
 public:  
   Car();  
   Car(char i[],char typ);  
   void input_data();  
   void input_data(char i[],char typ);  
   void show_data();  
   char* get_id();  
   char get_type();  
   void write_file();  
 };  
 Car::Car()  
 {  
 }  
 Car::Car(char i[],char typ)  
 {  
   strcpy(id,i);  
   type=typ;  
 }  
 void Car::input_data(char i[],char typ)  
 {  
   strcpy(id,i);  
   type=typ;  
 }  
 void Car::input_data()  
 {  
   cout << "\n\tEnter Car ID      : ";  
   gets(id);  
   cout << "\n\tEnter Car type(b,s)  : ";  
   cin >> type;  
 }  
 void Car::show_data()  
 {  
   cout << "\n\tCar ID       : " << id;  
   cout << "\n\tCar type      : " << type;  
 }  
 char* Car::get_id()  
 {  
   return id;  
 }  
 char Car::get_type()  
 {  
   return type;  
 }  
 void Car::write_file()  
 {  
   outfile << "\n\tCar ID       : " << id;  
   outfile << "\n\tCar type      : " << type;  
 }  
 //-----------------------------------------------------------------------------  
 //-----------------------------------------------------------------------------  
 //---------------------------Parking Class-------------------------------------  
 class Parking  
 {  
 private:  
   Car cob;  
   Driver dob;  
   int hour;  
   int charge;  
   int small_charge;  
   int big_charge;  
   char pay_status;  
 public:  
   Parking();  
   void input_data();  
   void show_data();  
   void cal_charge();  
   void payment();  
   int get_hour();  
   int get_charge();  
   char get_pay_status();  
   void write_file();  
   void read_file();  
 };  
 Parking::Parking()  
 {  
   pay_status='N';  
   small_charge=50;  
   big_charge=100;  
   charge=0;  
   hour=0;  
 }  
 void Parking::input_data()  
 {  
   cout << "\n\tEnter Car info";  
   cout << "\n\t--------------------------------" << endl;  
   dob.input_data();  
   cob.input_data();  
   cout << "\n\tEnter time in hour   : ";  
   cin >> hour;  
 }  
 void Parking::show_data()  
 {  
   cout << "\n\tCar info";  
   cout << "\n\t--------------------------------" << endl;  
   dob.show_data();  
   cob.show_data();  
   cout << "\n\tTime in hour    : " << hour;  
   cout << "\n\tTotal Charge    : " << charge;  
   cout << "\n\tPayment Status   : " << pay_status;  
 }  
 int Parking::get_hour()  
 {  
   return hour;  
 }  
 int Parking::get_charge()  
 {  
   return charge;  
 }  
 char Parking::get_pay_status()  
 {  
   return pay_status;  
 }  
 void Parking::cal_charge()  
 {  
   char ch;  
   ch = cob.get_type();  
   if(ch=='b')  
   {  
     charge= hour*big_charge;  
   }  
   if(ch=='s')  
   {  
     charge= hour*small_charge;  
   }  
 }  
 void Parking::payment()  
 {  
   int t;  
   do  
   {  
     cout << "\n\tPlease Pay amount " << charge << " BDT Only : ";  
     cin >> t;  
   }while(t!=charge);  
   pay_status= 'Y';  
   cout << "\n\n\n\t\t\t\tThank You for your corporation!!!\n\n\n\n";  
 }  
 void Parking::write_file()  
 {  
   outfile << "\n\tCar info";  
   outfile << "\n\t--------------------------------" << endl;  
   dob.write_file();  
   cob.write_file();  
   outfile << "\n\tTime in hour    : " << hour;  
   outfile << "\n\tTotal Charge    : " << charge;  
   outfile << "\n\tPayment Status   : " << pay_status;  
 }  
 void Parking::read_file()  
 {  
   cout << infile.rdbuf();  
 }  
 //-----------------------------------------------------------------------------  
 //-----------------------------------------------------------------------------  
 //---------------------------main function-------------------------------------  
 int main()  
 {  
   Parking pob;  
   int choise;  
   while(1)  
   {  
     cout << "\n\t************************************************";  
     cout << "\n\t\t    Choose Your Option";  
     cout << "\n\t\t  1.For parking car entry Your Info";  
     cout << "\n\t\t  2.Show entry Info";  
     cout << "\n\t\t  0.EXIT!!";  
     cout << "\n\t************************************************";  
     cin >> choise;  
     switch(choise)  
     {  
     case 1:  
       pob.input_data();  
       pob.cal_charge();  
       pob.show_data();  
       cout << "\n\t--------------------------------" << endl;  
       pob.payment();  
       pob.write_file();  
       break;  
     case 2:  
       pob.read_file();  
       break;  
     }  
     if(choise==0)  
       break;  
     cout << "\n\tPress any key for menu: ";  
       }  
   return 0;  
 }  
 //*********************************  
 /*parking.text  
 Car info  
   --------------------------------  
   Driver Name    : Ramjan  
   Car ID       : 1  
   Car type      : b  
   Time in hour    : 1  
   Total Charge    : 100  
   Payment Status   : Y  
   Car info  
   --------------------------------  
   Driver Name    : Mahbub  
   Car ID       : 2  
   Car type      : s  
   Time in hour    : 2  
   Total Charge    : 100  
   Payment Status   : Y  
   Car info  
   --------------------------------  
   Driver Name    : Rahul  
   Car ID       : 3  
   Car type      : s  
   Time in hour    : 1  
   Total Charge    : 50  
   Payment Status   : Y  
   Car info  
   --------------------------------  
   Driver Name    : Ebrahim  
   Car ID       : 4  
   Car type      : b  
   Time in hour    : 5  
   Total Charge    : 500  
   Payment Status   : Y*/  
 //  ************************************  

C Plus Plus Project : Student info

Cpp Project: Student info  

 ///====================CREARED BY JAMIUL ALAM===========================  
 #include<iostream>  
 #include<stdio.h>  
 #include<string.h>  
 #include<stdlib.h>  
 #include<fstream>  
 using namespace std;  
  class student  
  {  
  public:  
    char name[50],dept[30],ch,adress[40];  
    float id;  
   public:  
     void add_new(char*);  
     void show(char*);  
     void del_item(char*);  
     void search(char*);  
    };  
   void student::add_new(char fname[20])  
   {  
    int d,t,s,i;  
    char sub[30];  
    do  
    {  
    FILE *fp;  
    fp=fopen(fname,"a");  
    fopen(fname,"a");  
    cout<<"student Name: ";  
    //cin>>name;  
    gets(name);  
    cin.get(name,20);  
    cout<<"\nGiven Id: ";  
    cin>>id;  
    cout<<"\nDepartment: ";  
    cin>>dept;  
    cout<<"\nAddress= ";  
    gets(adress);  
    cin.get(adress,20);  
    fprintf(fp,"\t%s\t\t%0.1f \t\t\t%s\t\t\t%s\n",name,id,dept,adress);  
    fclose(fp);  
    system("cls");  
    cout<<"\n1.To add student.\n\n0.To Break\n";  
    cin>>d;  
    }  
    while(d!=0);  
   }  
   void student::show(char fname[20])  
    {  
     cout<<"--------------------------------------------------------------------------------\n";  
     cout<<"\tNAME\t\tId \t\t\tDEPARTMENT\t\tADDRESS\n"<<endl;  
     fstream fp;  
     fp.open(fname,ios::in);  
     while(fp)  
     {  
     fp.get(ch);  
     cout<<ch;  
     }  
     cout<<"--------------------------------------------------------------------------------\n\n";  
    }  
    void student:: del_item(char fname[20])  
    {  
      int k;  
      do  
     {  
     FILE *fp;  
     char temd[5000],del[100],m[5000];  
     int d,i,j=0,n=0,u=0;  
     printf("Enter the name you want to delete!\n");  
     scanf("%s",del);  
     fp=fopen(fname,"r");  
     for(d=0; del[d]!='\0'; d++)  
     {  
     }  
     fp=fopen(fname,"r");  
     while(fgets(temd, 5000, fp) != NULL)  
     {  
       if((strstr(temd, del)) != NULL)  
       {  
         u++;  
       }  
       else  
       {  
         for(i=0; temd[i]!='\0'; i++)  
         {  
           m[j]=temd[i];  
           j++;  
         }  
       }  
     }  
     fclose(fp);  
     fp=fopen(fname,"w");  
     for(n=0; n<j; n++)  
     {  
       if(m[n]==1)  
       {  
         fprintf(fp,"\n");  
       }  
       else  
       {  
         fprintf(fp,"%c",m[n]);  
       }  
     }  
     cout<<"\nname has been successfully DELETE from the list!\n";  
     if(u==0)  
       {  
         system("cls");  
         cout<<"\nSorry,there is no name.\nTry again!\n";  
       }  
     fclose(fp);  
     printf("\nTo Delete another name then press 1\n\nto stop press 0 !\n");  
     cin>>k;  
     }  
     while(k!=0);  
    }  
   void student::search(char fname[20])  
   {  
     FILE *fp;  
     char search[100],temd[5000];  
     int m,n;  
     do  
     {  
       fp=fopen(fname,"r");  
       n=0;  
       printf("Enter the name you want to search!\n");  
       scanf("%s",search);  
       system("cls");  
       while(fgets(temd, 5000,fp)!=NULL)  
       {  
         if(strstr(temd,search)!=NULL)  
         {  
           cout<<"Your search result:\n\n";  
           cout<<"-----------------------------------------------------------------------------------\n";  
           cout<<"\tNAME\t\tId \t\t\tDEPARTMENT\t\tADDRESS"<<endl;  
           cout<<"-------------------------------------------------------------------------------------\n";  
           printf("%s\n",temd);  
           n++;  
         }  
       }  
       if(n==0)  
       {  
         printf("\nSorry there is no name match '%s' in the list.\nTry again!\n\n",search);  
       }  
       printf("To search another student then press 1 \n\nto stop press 0 !\n");  
       cin>>m;  
     }  
     while(m!=0);  
   }  
  int main()  
  {  
    char m[15],name[20];  
    float id,l;  
    cout<<"Create your file first"<<endl;  
    cin>>m;  
    cout<<"\n\nUser name: ";  
    gets(name);  
    cin.get(name,20);  
    cout<<"\n\npassword: ";cin>>id;  
    system("cls");  
    student obj;  
    int x;  
   do{  
     cout<<endl<<"****************************************************"<<endl;;  
     cout<<"\n\tWELCOME TO DATABASE SYSTEM \n";  
     cout<<endl<<"****************************************************"<<endl;  
     cout<<"\n YOUR OPTIONS:\n";  
     cout<<"\n\n\t1. ADD NEW:";  
     cout<<"\n\n\t2. SHOW :";  
     cout<<"\n\n\t3. DELETE :";  
     cout<<"\n\n\t4. SEARCH :";  
     cout<<"\n\n\t5. EXIT\n";  
    cin>>x;  
   switch(x)  
   {  
     case 1: obj.add_new(m);  
       break;  
     case 2:obj.show(m);  
       break;  
     case 3: obj.del_item(m);  
       break;  
     case 4: obj.search(m);  
       break;  
     case 5: break;  
   }  
   }  
   while(x!=5);  
   return 0;  
   }  

C Plus Plus Project : FOOD Corner

Cpp Project: FOOD Corner  

 #include<iostream>  
 #include<stdio.h>  
 #include<string.h>  
 #include<stdlib.h>  
 #include<fstream>  
 #include<conio.h>  
 using namespace std;  
  class food  
  {  
  public:  
    int code,cd;  
    char w,item[20];  
    float price;  
   public:  
     void add_item();  
     void menu(char*);  
     void del_item();  
     void sell();  
    }obj;  
   void food::add_item()  
   {  
    int n;  
    do  
    {  
    FILE *fp;  
    fp=fopen("pjt.txt","a");  
    cout<<"Code No.:";  
    cin>>code;  
    cout<<"Food Item:";  
    cin>>item;  
    cout<<"Price:";  
    cin>>price;  
    fprintf(fp,"%s \t\t %d \t\t %0.2f \n",item,code,price);  
    fclose(fp);  
    cout<<"Add more! (1 = Yes/0 = No)\n";  
    cin>>n;  
    }  
    while(n!=0);  
   }  
   void food::menu(char r[20])  
    {  
     cout<<"---------------------------------------------------------\n";  
     cout<<"NAME\t\tCode\t\tPRICE"<<endl;  
     cout<<"---------------------------------------------------------\n";  
     fstream fp;  
     fp.open(r,ios::in);  
     while(fp)  
     {  
     fp.get(w);  
     cout<<w;  
     }  
     cout<<"---------------------------------------------------------\n";  
    }  
    void food:: del_item()  
    {  
     FILE *fp;  
     char t[6000];  
     char del[20],m[6000];  
     int d,i,j=0,n=0;  
     printf("\nEnter the Food Item: ");  
     scanf("%s",del);  
     for(d=0; del[d]!='\0'; d++)  
     {  
     }  
     fp=fopen("pjt.txt","r");  
     while(fgets(t, 6000, fp) != NULL)  
     {  
       if((strstr(t, del)) != NULL)  
       {  
       }  
       else  
       {  
         for(i=0; t[i]!='\0'; i++)  
         {  
           m[j]=t[i];  
           j++;  
         }  
       }  
     }  
     fclose(fp);  
     fp=fopen("pjt.txt","w");  
     for(n=0; n<j; n++)  
     {  
       if(m[n]==1)  
       {  
         fprintf(fp,"\n");  
       }  
       else  
       {  
         fprintf(fp,"%c",m[n]);  
       }  
     }  
     fclose(fp);  
    }  
    void food::sell()  
   {  
     int j;  
    FILE *fp;  
     fp=fopen("pjt.txt","r");  
     do  
     {  
      cout<<"\nEnter Food Code:\n";  
      cin>>cd;  
      if(cd==code)  
     {  
      printf("%s \t\t %d \t\t %0.2f \n",item,code,price);  
     }  
     else{printf("No food available\n");  
     }  
     printf("Press 0 to quit :");  
     cin>>j;  
     if(j==0)  
       break;  
     }  
    while(fp);  
    fclose(fp);  
 }  
  int main()  
  {  
    char r[20]="pjt.txt";  
    int x;  
   do{  
     cout<<endl<<"****************************************************"<<endl;;  
     cout<<"\n\tFOOD Corner\n";  
     cout<<endl<<"****************************************************"<<endl;  
     cout<<"\nCHoose Your Option:\n";  
     cout<<"\n1. Show all food items:";  
     cout<<"\n2. Add a new item:";  
     cout<<"\n3. Delete items:";  
     cout<<"\n4. Sell Items";  
     cout<<"\n5. Quit\n";  
     cout<<"\nEnter Your Choice: ";  
    cin>>x;  
   switch(x)  
   {  
     case 1:obj.menu(r);  
       break;  
     case 2:obj.add_item();  
       break;  
     case 3: obj.del_item();  
       break;  
     case 4: obj.sell();  
     case 5:exit(0);  
   }  
   }  
   while(x!=5);  
   return 0;  
   }  



Friday, February 6, 2015

C Plus Plus Project : Data Entry

Cpp Project: Data Entry  

 #include<iostream>  
 #include<string>  
 #include<stdlib.h>  
 #include <fstream>  
 using namespace std;  
 class patient{  
 public:  
     char name1[100];  
     char name2[100];  
     int age;  
     char blood[20];  
     char date[20];  
     char *dept;  
     char *doc;  
     int a;  
     int t;  
     int dat,mon,yer;  
     double price,lab,total;  
     ofstream myfile;  
 public:  
     void input()  
     {  
         system("cls");  
         system("color D");  
         cout<<"\nENTER PATIENT 1ST NAME=";  
         cin>>name1;  
         cout<<"\nENTER PATIENT LAST NAME=";  
         cin>>name2;  
         cout<<"\nAGE=";  
         cin>>age;  
         cout<<"\nBLOOD GROUP=";  
         cin>>blood;  
         cout<<"\nDATE=";  
         cin>>dat;  
         cout<<"\nMONTH=";  
         cin>>mon;  
         cout<<"\nYEAR=";  
         cin>>yer;  
         cout<<"\n\n";  
         cout<<"\nTEST--\n\n"<<"\n";  
         cout<<"\n 1.EMERGENCY"<<"\n";  
         cout<<"\n 2.BLOOD TEST"<<"\n";  
         cout<<"\n 3.PATHOLOGY TEST"<<"\n";  
         cout<<"\n 4.URINE TEST"<<"\n";  
         cout<<"\n 5.CITY SCAN"<<"\n";  
         cout<<"\n 6.ULTRASONOGRAPHY"<<"\n";  
         cout<<"\n 7.ECG"<<"\n";  
         cout<<"\n 8.Endoscopy"<<"\n";  
         cin>>a;  
         try{  
             if(a==1)  
             {  
                 dept="EMERGENCY";  
                 doc="DR.MASSUM";  
             }  
             else if(a==2)  
             {  
                 dept="BLOOD TEST";  
                 doc="DR.RIAD";  
              }  
             else if(a==3)  
             {  
                 dept="PATHOLOGY TEST";  
                 doc="DR.RAHUL";  
             }  
             else if(a==4)  
             {  
                 dept="URINE TEST";  
                 doc="DR.MARUF";  
             }  
             else if(a==5)  
             {  
                 dept="CITY SCAN";  
                 doc="DR.AHSAN";  
             }  
             else if(a==6)  
             {  
                 dept="ULTRASONOGRAPHY";  
                 doc="DR.TUMPA";  
             }  
             else if(a==7)  
             {  
                 dept="ECG";  
                 doc="DR.SAFIUUDIN";  
             }  
             else if(a==8)  
             {  
                 dept="Endoscopy";  
                 doc="DR.ARIF";  
             }  
             else  
             {  
                 throw(a);  
             }  
         }  
         catch(int)  
         {  
             cout<<"\nWRONG INFORMATION!"<<"\n";  
             exit(1);  
         }  
     }  
     void display()  
     {  
             cout<<"\n\t\tNAME"<<"\t\tBLOOD"<<"\t\tAGE=\n\t\t";  
             for(int t=0;t<55;t++)  
             {  
               cout<<"=";  
             }  
             cout<<"\n\t\t"<<name1<<" "<<name2;  
             cout<<"\t"<<blood;  
             cout<<"\t\t"<<age;  
             cout<<"\n\t\tDate"<<"\t\tPatient Test"<<"\t\tDoctor name\n\t\t";  
             for(t=0;t<55;t++)  
             {  
             cout<<"=";  
             }  
             cout<<"\n\t\t"<<dat<<"/"<<mon<<"/"<<yer;  
             cout<<"\t"<<dept;  
             cout<<"\t\t"<<doc<<"\n\n";  
     }  
     void amount()  
     {  
         cout<<"\n\nLab Charge 200 TK"<<"\n";  
         lab=200;  
         if(a==1)  
         {  
            price=1000;  
         }  
         else if(a==2)  
         {  
            price=500;  
         }  
         else if(a==3)  
         {  
            price=1000;  
         }  
         else if(a==4)  
         {  
            price=1000;  
         }  
         else if(a==5)  
         {  
            price=5000;  
         }  
         else if(a==6)  
         {  
            price=2000;  
         }  
         else if(a==7)  
         {  
             price=4000;  
         }  
         else if(a==8)  
         {  
             price=3000;  
         }  
         else  
         {  
             cout<<"\nWRONG INFORMATION!"<<"\n";  
             exit(1);  
         }  
         total=price+lab;  
         display();  
         file_write();  
         cout<<"\nTOTAL FEES="<<total;  
     }  
     void file_write()  
     {  
         myfile.open("diagnostic center.txt", ios::app);  
         myfile<<"Lab Charge 200 TK"<<"\n";  
         myfile<<"\n\t\tNAME"<<"\t\tBLOOD"<<"\t\tAGE=\n\t\t";  
       for(int t=0;t<55;t++)  
       {  
        myfile<<"=";  
       }  
       myfile<<"\n\t\t"<<name1<<" "<<name2;  
       myfile<<"\t"<<blood;  
       myfile<<"\t\t"<<age;  
       myfile<<"\n\t\tDate"<<"\t\tPatient Test"<<"\t\tDoctor name\n\t\t";  
       for(t=0;t<55;t++)  
       {  
         myfile<<"=";  
       }  
       myfile<<"\n\t\t"<<dat<<"/"<<mon<<"/"<<yer;  
       myfile<<"\t"<<dept;  
       myfile<<"\t\t"<<doc;  
       myfile<<"\nTOTAL FEES="<<total;  
       myfile<<"\n\n\n";  
       myfile.close();  
     }  
 };  
 int main()  
 {  
     int n,i=0;  
     patient x1[100];  
     int num;  
     char ch;  
     do{  
         system("cls");  
         system("Color B");  
         cout<<"\nDATA ENTRY:";  
         cout<<"\n\n\t\tADMIT PATIENT [1]";  
         cout<<"\n\n\t\tVIEW LIST OF TESTS [2]";  
         cout<<"\n\n\t\tTOTAL AMOUNT [3]";  
         cout<<"\n\n\t\tEXIT [4]\n\t\t";  
         cin>>num;  
         switch(num)  
         {  
         case 1:  
             system("cls");  
             system("Color 1E");  
             cout<<"\nHOW MANY PATIENT=";  
             cin>>n;  
             for(i=0;i<n;i++)  
             {  
               x1[i].input();  
             }  
             cout<<"\nPLEASE PRESS ANY KEY FOR THE MAIN MENU";  
             cin>>ch;  
             break;  
         case 2:  
             system("cls");  
             system("Color 1E");  
             cout<<"\nLIST OF TESTs--";  
             for(i=0;i<n;i++)  
             {  
               x1[i].display();  
             }  
             cout<<"\nPLEASE PRESS ANY KEY FOR THE MAIN MENU";  
             cin>>ch;  
             break;  
         case 3:  
             system("cls");  
             system("Color 1E");  
             cout<<"\nTOTAL AMOUNT=";  
             for(i=0;i<n;i++)  
             {  
               x1[i].amount();  
             }  
             cout<<"\nPLEASE PRESS ANY KEY FOR THE MAIN MENU";  
             cin>>ch;  
             break;  
         case 4:  
             break;  
         }  
     }  
     while(num!=4);  
     return 0;  
 }