Sunday, December 31, 2017

Worst Passwords of 2017

Very interesting article posted by NBCNews (one of the world leading news agency); the top five Worst Passwords of 2017, according to the just-released list from the password management company SplashData, are as under:

Top 5 Worst Password of 2017

123456
Password
12345678
Qwerty
12345

For more details visit following URL.

[ Reference:https://www.nbcnews.com/better/tech/top-5-worst-passwords-2017-how-choose-one-s-secure-ncna833186]

Windows Message Box using C Program

C program to print message in Windows Message Box.


#include <windows.h>
int _stdcall WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
MessageBox ( 0, "Greetings!!!\n C Program Practicals", "MyWindow", 0 ) ;
return 0 ;
}

Output of program

This program will display following message in Windows message box.

Windows Message Box
Windows Message Box using C Program

Program of System Date and Time

C program to read System Date and Time.
#include <stdio.h>
#include <time.h>

int main()
{
   time_t t;
   time(&t);
      printf("System date and time is: %s",ctime(&t));
   getch();
   return 0;
}

Output of program

System date and time is: Sun Dec 31 15:49:15 2017

Monday, December 18, 2017

kbhit() funtion

Use of kbhit () function..

#include <stdio.h>
#include <conio.h>

int main()
{
   char ch;
   while (!kbhit())
   {
      printf("Press any key...\n");
      ch = getch();
      printf("You have pressed %c.\n",ch);
   } 
   return 0;
}

Sunday, December 17, 2017

Wireless Security Measures

Following important wireless security measures can be used to prevent wireless security related attacks.

  • SSID hiding
  • MAC ID filtering (Physical Address)
  • 802.11 security
  • Static IP addressing
  • Regular and Advanced WEP
  • Restricted access networks
  • End-to-end encryption (Cryptographic Techniques)
More details about these keywords are posted soon.

Tuesday, December 5, 2017

Top Flowchart Software

What is Flowchart?

A flowchart is a type of diagram which may represents some workflow, an algorithm or process. It shows the steps as boxes; and their order by connecting arrows. This diagrammatic representation illustrates a solution model to a given problem.


Top Flowchart Software

Some of the top Flowchart Drawing Software are as under:

  • Lucidchart
  • Visio
  • Edraw
  • ConceptDraw
  • Cacoo
  • SmartDraaw
  • Creately
  • Raptor
  • RFFlow
  • Flowgorithm
  • yEd
  • Visual Logic
* * *

Tuesday, November 28, 2017

Split file into 3 equal files.

C++ Program to Split file into 3 equal files.

This program will take input from data.txt file and split it into 3 equal size files (data1.txt, data2.txt, data3.txt).


#include<iostream>
#include<fstream>

using namespace std;
int main()
{
ifstream fin;
ofstream fout1, fout2, fout3;
char ch;
int i, cnt=0, equal_part=0, last_part=0;
fin >> std::noskipws;

fin.open("data.txt");
if(!fin){  
    cout<<"Error Open Error."; exit(1); 
}

//logic to count total character in input data file
while(fin.eof()==0){
fin >> ch;
cnt++;
}
cout << "Total characters in data.txt file = "<< cnt-1 << endl;
fin.close();
//logic to divide no. characters in each file
equal_part = (cnt-1)/3;
last_part = (cnt-1)%3;
cout <<"Total files to be created=3."<< endl;
cout << "Each output file contains: "<<equal_part <<" characters."<<endl;
cout << "Last output file contains: "<<equal_part+last_part<<" characters."<<endl;

fin.open("data.txt");
fin >> std::noskipws;

fout1.open("data1.txt");
if(!fout1){ 
cout<<"File data1.txt Open Error.";  exit(1);
}
for(i=0; i<equal_part; i++) {
fin >> ch;
fout1 << ch;
}

fout2.open("data2.txt");
if(!fout2){ 
cout<<"File data2.txt Open Error.";  exit(1);
}

for(i=0; i<equal_part; i++)
{
fin >> ch;
fout2 << ch;
}

fout3.open("data3.txt");
if(!fout3){ 
cout<<"File data3.txt Open Error.";  exit(1);
}
for(i=0; i<equal_part+last_part; i++)
{
fin >> ch;
fout3 << ch;
}

fin.close();
fout1.close();
fout2.close();
fout3.close();

return 0;
}

Output of program

Total characters in data.txt file = 10
Total files to be created=3.
Each output file contains: 3 characters.
Last output file contains: 4 characters.

Tuesday, November 21, 2017

C++ Program to copy files.

#include<iostream>
#include<fstream>

using namespace std;
int main()
{
ifstream fin;
ofstream fout;
char ch, fname1[20], fname2[20];

fin >> std::noskipws; //To copy whitespace characters

cout<<"Enter source file name: ";
gets(fname1);
fin.open(fname1);

if(!fin){
cout<<"Error Open Error.";
exit(1);
}

cout<<"Enter target file name: ";
gets(fname2);
fout.open(fname2);

if(!fout){
cout<<"File Open Error.";
exit(1);
}
//Logic to copy data from file1 to file2
while(fin.eof()==0){
fin >> ch;
fout << ch;
}
cout<<"File content copied successfully...";

fin.close();
fout.close();
return 0;
}

Output of program

Enter source file name: file1.txt
Enter target file name: file2.txt
File content copied successfully...

Friday, November 17, 2017

C++ File Operations on Binary Files

This C++ file management program will append data into a binary file.
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
class student
{
  int rollno;
  char name[20];
  char dept[10];

  public:
void getdata()
{
cout << "Rollno: ";
cin >> rollno;

cout << "Name: ";
cin >> name;

cout << "Branch: ";
cin >> dept;
}
};

int main()
{
  student s1;
  char ans='y';

  ofstream fout("student.txt", ios::app);

  while(ans=='y' || ans=='Y')
  {
s1.getdata();
fout.write((char *)&s1, sizeof(s1));
cout<<"Data appended in file successfully.\n";
cout<<"\nWant to add more data? (y/n)..";
cin>>ans;
  }

  fout.close();
  return 0;
}

Output of program:

Rollno: 101
Name: Amit
Branch: MCA
Data appended in file successfully.

Want to add more data? (y/n)..y
Rollno: 102
Name: Sunit
Branch: PhD
Data appended in file successfully.

Want to add more data? (y/n)..n

Tuesday, November 14, 2017

Use of fprintf and fscanf

File management: Program to demonstrate use of fprintf() and fscanf() function. This program will read a word from keyboard and write it into a data.txt file. After closing a file, program will again open it and get a word from file and display on screen.



#include <stdio.h>
#include <stdlib.h>
int main()
{
  FILE *fp;
  char str[80], str1[80];

  fp = fopen("data.txt","w");

  if(fp == NULL)
  {
printf("Cannot open file.\n");
exit(1);
  }
  printf("Enter string to be written in a file: ");
  fscanf(stdin, "%s", str); /*Read from keyboard */

  fprintf(fp, "%s", str); /*Write str to file */
  fclose(fp);

  fp = fopen("data.txt","r");

  if(fp == NULL) {
printf("Cannot open file.\n");
exit(1);
  }
  fscanf(fp, "%s", str1); /* read a word from file and copy into str1 */
  fprintf(stdout, "%s", str1); /* print str1 on screen */
  return 0;
}

Output of program

Enter string to be written in a file: Hello
Hello

Monday, October 23, 2017

Reading a line in C++





C++ program to read a line using getline() function.

#include <iostream>
#include <string>
using namespace std;

int main ()
{
    string my_str;
    
    cout << "Enter your name:";
    getline (cin, my_str);
    cout << "Your name is " << my_str;
    
    return 0;
}

Output of program

Enter your name:SCS AU
Your name is SCS AU

Friday, October 20, 2017

Decimal to Hexadecimal and Octal in C++

Decimal to Hexadecimal and Octal in C++.
This program will display decimal number into Hexadecimal and Octal.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
  int number=100;
  cout << "Hexadecimal of 100 is: ";
  cout << hex << number << endl;
  cout << "Octal of 100 is: ";
  cout << oct << number << endl;
  return 0;
}

Output of program

Hexadecimal of 100 is: 64
Octal of 100 is: 144


Formatted output in C++


Formatted output in C++
#include <iostream>
using namespace std;
int main()
{
  cout.precision(5) ;
  cout.width(10);
  cout << 12.345678 << "\n"; // output 12.346

  cout.fill('-');
  cout.width(10);
  cout << 12.345678 << "\n"; // output ----12.346

cout.width(10);
  cout << "Hello!" << "\n"; // Output ----Hello!
  cout.width(10);

cout.setf(ios::left); // left justify
  cout << 12.345678; // Output 12.346----
  return 0;
}

Output of program

    12.346
----12.346
----Hello!
12.346----

Sunday, October 15, 2017

Read one word from a file.



Following C++ program will read a word from data.txt file stored in the same location where source program is stored.

#include <fstream>
#include <iostream>
using namespace std;

int main () {
   
   char word[20];

   ifstream fin;    //open file to read.
   fin.open("data.txt");
 
   cout << "Reading a word from a file...\n";
   
   fin >> word;
   cout << word;    //write data to screen.
 
   fin.close();     //close the opened file.
   return 0;
}

Output of program

Reading a word from a file...
hello

Tuesday, October 10, 2017

FTP server client simulation using socket program

This JAVA socket program will download webpage (HTML file) from server to client. Downloaded file will be opened into web browser.

SERVER side program

import java.io.*;
import java.net.*;

public class FTPServer {
  public static void main(String[] args) throws IOException {
    //server will start at port number 12345.
    ServerSocket servsock = new ServerSocket(12345);

    //server will send index1.htm file to client.
    File myFile = new File("D:\\index1.htm");
    System.out.println("Waiting for Client Request...");
    while (true) {
      Socket sock = servsock.accept();
      byte[] mybytearray = new byte[(int) myFile.length()];
      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile));
      bis.read(mybytearray, 0, mybytearray.length);
      OutputStream os = sock.getOutputStream();
      os.write(mybytearray, 0, mybytearray.length);
      os.flush();
      sock.close();
    }
  }
}

SERVER side Output:

Waiting for Client Request...



CLIENT side program

import java.awt.Desktop;
import java.io.*;
import java.net.*;

public class FTPClient {
  public static void main(String[] argv) throws Exception {

    //socket will be created local IP: 127.0.0.1 and port 12345.
    Socket sock = new Socket("127.0.0.1", 12345);
    byte[] mybytearray = new byte[1024];
   
    InputStream is = sock.getInputStream();
    FileOutputStream fos = new FileOutputStream("D:\\index2.htm");
    BufferedOutputStream bos = new BufferedOutputStream(fos);
   
    int bytesRead = is.read(mybytearray, 0, mybytearray.length);
    bos.write(mybytearray, 0, bytesRead);
   
    System.out.println("File downloaded...");
   
    Following code will open index2.htm file in browser.

    String url="D:\\index2.htm";
    File htmlFile=new File(url);
    Desktop.getDesktop().browse(htmlFile.toURI());

    bos.close();
    sock.close();
  }
}

CLIENT side output:

File downloaded...
BUILD SUCCESSFUL (total time: 1 second)



Thursday, September 21, 2017

2G 3G 4G 5G Technology

1G, 2G, 3G, 4G અને 5G ટેક્નોલોજી

  • 1જી (અથવા 1-જી) વાયરલેસ ટેલિફોન ટેકનોલોજીની પ્રથમ પેઢી (મોબાઇલ ટેલિકોમ્યુનિકેશન)ની ટેક્નોલોજી છે. તે એનોલોગ ટેલિકમ્યુનિકેશન પર કામ કરે છે અને 1980 ના દાયકામાં પ્રચલિત હતી
  • 2 જી (અથવા 2-જી) ટેક્નોલોજી 1જી  કરતા ત્રણ વધારાના લાભો પૂરા પાડે છે
    • તેમાં ફોન પરની વાતચીત ડિજિટલ એન્ક્રિપ્ટ કરવામાં આવે છે  જે વધારે સુરક્ષિત છે.
    • 2 જી સિસ્ટમો પર ઘણાં વધુ મોબાઇલ ફોન એક સાથે વાપરી શકાય છે, તેથી સ્પેક્ટ્રમ પર વધુ કાર્યક્ષમ છે;
    • 2 જી મોબાઇલમાં ડેટા સેવાઓ વાપરી શકાય છે. જેમ કે એસએમએસ (શૉર્ટ મેસેજ સર્વિસ) મોકલી શકાય છે. 2 જી થી ટેક્સ્ટ સંદેશાઓ, ચિત્ર સંદેશાઓ અને એમએમએસ (મલ્ટિમિડીયા સંદેશ સેવા) જેવી સેવાઓ પૂરી પડી શકાય છે.
  • 3G ટેકનોલોજી ઓછામાં ઓછા 200 kbit / s ની માહિતી ટ્રાન્સફર રેટ પૂરી પાડે છે.
  • 4જી ટેક્નોલોજી વૉઇસની સાથે સાથે, મોબાઇલ બ્રોડબેન્ડ ઇન્ટરનેટ એક્સેસ, વાયરલેસ મોડેમ સાથેના લેપટોપ્સ અને સ્માર્ટફોન્સમાં સુવિધાઓ પૂરી પાડે છે. 4જી આધારિત કેટલીક એપ્લિકેશન્સ આ પ્રમાણે છે: મોબાઇલ વેબ ઍક્સેસ, ગેમિંગ, આઇપી ટેલિફોની, મોબાઇલ ટીવી અને  વિડીયો કોન્ફરન્સિંગ.
  • 5જી એ પાંચમી પેઢીની નવીનતમ મોબાઇલ વાયરલેસ સ્ટાન્ડર્ડ છે. 5જી એ 4જી કરતાં વધુ ઝડપી હશે, 10,000 એમબીપીએસની સૈદ્ધાંતિક ડાઉનલોડ સ્પીડ સાથે તમામ સક્ષમ ઉપકરણોમાં ઉચ્ચ ઉત્પાદકતા માટે પરવાનગી આપશે.
* * * * *

Friday, September 1, 2017

Program to check Armstrong number

Example of Armstrong number

153 = 1*1*1 + 5*5*5 + 3*3*3

An Armstrong number of three digits is the integer number such that the sum of the cubes of its all digits is equal to the number itself.


Program to check Armstrong number

#include <stdio.h>
int getPower(int, int);

int main()
{
   int num, tmp, total = 0, remainder, no_of_digits = 0;

   printf("Enter integer number: ");
   scanf("%d", &num);
   tmp = num;
   // Count number of digits in given number
   while (tmp != 0) 
   {
      no_of_digits++;
      tmp = tmp/10;
   }
  //Logic to get total as per Armstrong formula.
   tmp = num;
   while (tmp != 0) 
   {
      remainder = tmp%10;
      total = total + getPower(remainder, no_of_digits);
      tmp = tmp/10;
   }

   if (total == num)
      printf("%d is Armstrong number.", num);
   else
      printf("%d is not Armstrong number.", num);

   return 0;
}

int getPower(int n1, int r1) {
   int i, power=1;

   for (i=1; i<=r1; i++) 
      power = power * n1;

   return power;   
}

Output-1
Enter integer number: 153
153 is Armstrong number.

Output-2
Enter integer number: 125
125 is not Armstrong number.


Thursday, August 31, 2017

Friend function in c++

A friend function is a function defined outside of C++ class. But it has the right to access all private and protected members of the class. Prototypes for friend functions appear in the class definition. The friends are not member functions.
Use of Friend function in C++
#include <iostream>
using namespace std;

class Student {
   double percen;
public:
   friend void printPercen( Student s1 );
   void setPercen( double per );
};

void Student::setPercen( double per ) {
   percen = per;
}

// printPercen() is not a member function of any class.
void printPercen( Student s1 ) {

/*printPercen() is a friend of Student class,hence can access any member of Student class*/

   cout << "Percentage of s1: " << s1.percen;
}

int main( ) {
   Student s1;
   s1.setPercen(90.5);
   // Use friend function to print the percentage.
   printPercen( s1 );
   return 0;
}

Output of program:

Percentage of s1: 90.5

Sunday, August 20, 2017

Fahrenheit to Celsius using Class


Program to convert Fahrenheit to Celsius using Class.

#include<iostream>
using namespace std;
class Temperature
{
   float f,c;

   public:
      void  readFahrenheit(){
cout<<"Enter Fahrenheit degree: ";
cin>>f;
     }
      void convertToCelsius(void){
//float v;
c = (f-32)/1.8;
cout<<"Celsius Degree = "<<c;      
      }
};

int  main()
{
Temperature c;
c.readFahrenheit();
c.convertToCelsius();
return 0;
}

Output of program

Enter Fahrenheit degree: 200
Celsius Degree = 93.3333