Sunday, 29 January 2023

Java Program to find the Prime numbers using values from Terminal as input through (String [] args)

class PrimeNo
{
    public static void main(String[] args) /*String []args will take
input from the terminal(cmd command line) directly */
    {
        int n;
        for(int i=0;i<args.length;i++) /* using length function to get the total
length of the one dimensional array*/
        {
            int j=2;
            n=Integer.parseInt(args[i]); /*using parseInt function
from Integer class to convert the
numbers (which are in String) into the integer*/
            for(;j<=Math.sqrt(n);j++)
            {
                if(n%j==0)
                    break;
            }
            if(j>Math.sqrt(n))
                System.out.println(n+" = Prime Number");
            else
                System.out.println(n+" = Not Prime Number");
        }
    }
}

Sunday, 15 January 2023

Day Name Finder using C++


 

#include<iostream>    //use iostream.h in TurboC++
#include<conio.h>

using namespace std;   //comment this line in TurboC++ 

int dayofweek(int d,int m,int y)
{
static int t[]={0,3,2,5,0,3,5,1,4,6,2,4};
y-=m<3;
   /*if(m<3)   //this (if) line and the above line of code is same as for the functioning aspect
y-=m;*/
return(y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
int main(void)
{
int d,m,y;
cout<<"\nDay Name Finder \"Enter the below data to find the day on that date:\" ";
cout<<"\n\nEnter date: ";
cin>>d;
cout<<"\nEnter Month: ";
cin>>m;
cout<<"\nEnter Year: ";
cin>>y;
cout<<"\nThe Day on this date is ->: ";
switch(dayofweek(d,m,y))
{
case 0:cout<<" Sunday";break;
case 1:cout<<" Monday";break;
case 2:cout<<" Tuesday";break;
case 3:cout<<" Wednesday";break;
case 4:cout<<" Thursday";break;
case 5:cout<<" Friday";break;
case 6:cout<<" Saturday";break;
}
//getch();   //Use this line in TurboC++ to hold Console Screen
}

Sunday, 8 January 2023

Airline Reservation System Project in C++

 


/*(Note
: This will work on any Modern compiler is you want to use this in TurboC++ then do some necessary change needed in TurboC++ then it is good to go.)*/

#include<iostream>

#include<conio.h>

#include<fstream>

#include<stdlib.h>

#include<iomanip>


using namespace std;

class flightDetails

{

double flamt;

char flnum[100], flname[100], flfrom[200], usdestin[200], fltime[100];

int columnID;

char opt;


public:

void fldisplay();

void flgetdata();

};

flightDetails f;


void flightDetails::fldisplay()

{

fstream file2;

file2.open("flightDetails1234.txt",ios::in | ios::out | ios::binary);

if(!file2)

{

cout << "\n File Not Found!!!!";

file2.close();

return;

}

cout << "\n------------------------------------------------------------------------------------------" << endl;

cout << "\n| columnID | "<< "| Flight No |"<< "| From |"<< "| To |"<< "| Flight Time |"<< "| Amount |" << endl;


file2.seekg(0,ios::beg);

while (file2.read((char *)&f, sizeof(f)))

{

cout<< " | " <<columnID << "     | " << flnum << "     | " << flfrom << "     | " << usdestin << "     | " << fltime << "     | " << flamt << "     | " << endl;

cout<< "----------------------------------------------------------------------------------------------------------------------------------------------" << endl;

}

file2.close();

}

void flightDetails::flgetdata()

{

fstream file; //will be able to read and write into the file

int flag = 0;

columnID=1;

file.open("flightDetails1234.txt", ios::in | ios::app | ios::binary);

file.seekp(0, ios::end);

cout << "\n Enter Flight Number: ";

cin>>flnum;

cout << "\n Enter Flight Name: ";

cin>>flname;

cout << "\n Enter Flight From: ";

cin>>flfrom;

cout << "\n Enter Flight destination: ";

cin>>usdestin;

cout<< "\n Enter Flight Time (in HH:MM format): ";

cin>>fltime;

cout << "\n Enter Flight amout: ";

cin >> flamt;

cout << "\n Enter Flight Availability: (A (Available) / N (Not Available)): ";

cin >> opt;

if (opt == 'A' || opt == 'a')

{

if(file)

{

file.seekp(0,ios::end);

file.write((char *)&f,sizeof(f));

//file<<columnID<<setw(10)<<flnum<<setw(20)<<flname<<setw(20)<<left<<flfrom<<left<<usdestin<<left<<setw(20)<<fltime<<left<<setw(20)<<flamt<<endl;

flag = 1;

cout << " Successfully Added into the file...."<<endl;

}

else

{

cout << "Unable to Open / Write into the File." << endl;

}

if (flag == 1)

{

columnID += 1;

}

}

else

cout << "The Flight Is Not Available" << endl;


file.close();

fldisplay();

}

int main(void)

{

cout << "\nWelcom to Airlines Reservation System";

cout << "\n---------------------------------------------------";

f.flgetdata();

system("pause");

return 0;

}


Monday, 2 January 2023

Magic Matrices using C language

 

#include<stdio.h>

#include<conio.h>

int main(void){

    char ans;

    int a[15][15],i,j,k,l,m,x,y,n;

    do{

        ejaz:

        //clrscr();                   //this line will work in TurboC++  to clear the console

        printf("\n Enter any odd number b/n 3 to 15 to get magic matrix: ");

        scanf("%5d",&n);

        if(n%2==0||n<3||n>15)

        goto ejaz;

        for(j=(n-1)/2,k=1,i=0,l=0;l<n;l++){

            for(m=1;m<=n;i--,j--,m++,k++){

                if(j<0)

                j=n-1;

                if(m<=n&&i+1==0)

                i=n-1;

                a[i][j]=k;

            }

            i+=2;

            j++;

        }

        printf("\n\n");

        for(y=3,i=0;i<n;i++,y+=3){

            for(x=5,j=0;j<n;j++,x+=5){

               //gotoxy(x,y);                          //gotoxy can give printing location to curser in TurboC++  

               printf("%5d",a[i][j]);

            }

            printf("\n\n");                      // this line does not needed in TurboC++, the gotoxy is all it needed

        }

        printf("\n Want to continue y/n:  ");

        fflush(stdin);           // fflush(stdin) is uesd to clear the garbage from standard input stream

        ans=getchar();

    }while(ans=='y'||ans=='Y');

    //getch();                //this line will work in TurboC++  to hold screen of the console

}