File Handling: Write operation C++

Write a program in C++ to perform Write operation with in a file.

Here we are going to do two things:

i) Open the file.

ii) Ask user to write into the File and finally show the content of the file.

PROGRAM:

#include<iostream>
#include<stdio.h>
#include<fstream>
using namespace std;

int main()
{
    char c,fname[10];
    ofstream out;
    cout<<"Enter File name:";
    cin>>fname;
    out.open(fname);
    cout<<"Enter contents to store in file (Enter # at end):n";
    while((c=getchar())!='#')
         {
          cout<<c;
         }
    out.close();
    return 0;
}

 

OUTPUT:

file handling

Why keyboard layout is QWERTY not ABCDEF ?

 

It hasn’t been done randomly or just for fun, it has a very distinct and purposeful reason behind it.

qwerty
The current format of the keyboard was devised long back in 1870’s by a gentleman named Christopher Sholes. Though, it definitely was not the first format to come up, it didn’t take much time to switch to this one. Starting with lexicographic order i.e. A-B-C-D-E-F, after various trials and errors and taking hundreds of cases, Christopher Sholes gradually reached the Q-W-E-R-T-Y. It was really well received (evident from the fact that we still use it).

When the typewriter was invented, it used a metal bar to hold the character alphabets and the other end of the bar was attached to a linkage carrying a carriage with the coated ink. When a key was struck, it would emboss its character on the paper placed beneath the carriage. However, when an operator learned to type at a great speed, a certain flaw invoked. When two letters were struck in quick succession, the bars of the typewriter would entangle and get jammed.

Christopher Sholes found a way out. He proposed that the letters of frequently used letter pairs should be in different rows. For example, ‘C-H’, ‘S-T’, ’T-H’, ‘W-H’ and more. He also formulated that to speed up the typing process, there has to be a regular alternation between two hands. So observing thousands of words, he placed the letters in way that most words would make use of both hands.

He also observed that almost every word in the dictionary carries a vowel. According to him, the most frequently used vowel was ‘A’ and the most frequently used letter (non-vowel) was ‘S’. So he placed ‘A’ and ‘S’ together and chose to keep less common letters like ‘Q’, ‘W’, ‘Z’, ‘X’, ‘C’ around these. This was complemented by placing fairly common letters like ‘M’, ‘N’, ‘L’, ‘K’, ‘O’, ‘P’ at right extremes to create a perfect alternation between both the hands.

All these factors tested with thousands of trials gave us the format that we still use and perhaps would be using till eternity.

11 Nerdy Facts About Bill Gates

Some Facts about Bill Gates, The World’s richest man(was):

1.  Bill Gates’ first program was a tic – tac – toe game.


tic-tac-toe


​2. At Harvard he told professors he would be a millionaire by 30.He became a billionaire aged 31.


bill gates at harvard



3. Interestingly enough, Microsoft wasn’t Bill and Paul Allen first venture. They had come together earlier to create Traf-O-Data, a company that made traffic counters built on the Intel 8008 processor.


bill gates paul allen


4. He paid $30.1 million at an auction in 1994 for the Codex Leichester, a collection of writing by Leonardo Da Vinci.



da vinci writings


5. His net worth briefly surpassed $101 billion 1999, causing the media to call “centibilionaire.”

6. On December 9, 2010, Gates, investor Warren Buffett, and Mark Zuckerberg (Facebook’s CEO) signed the “Gates-Buffet Giving Pledge”, in which they promised to donate to charity at least half of their wealth.


bill gtaes warren buffet mark zukerburg



7. Gates pays almost $1 million in property taxes for his home, a magnificent house overlooking Lake Washington that is estimated to be worth $125 million.


medina-bill-gates-house


8. What does Bill Gates, Julia Roberts, Brad Paisley and Frank Ocean have in common? They all share the same birthday, October 28.

9. Gates wife and children are not allowed to own or use an Apple product. A restriction was also put in place by Steve Balmer for his family.


apple restriction

10. Out of Gates approx.78.5 billion dollars, his children will inherit only 10 million dollars each.

11. If Bill Gates were a country, he would be the 37 th country in terms of wealth.

 

Enjoyed!!! Share this.

Program to implement Depth First Search C++

What is Depth First Search? Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some arbitrary node as the root in the case of a graph) and explores as far as possible along each branch before backtracking. A version of depth-first search was … Read more

Default Arguments C++: Look at them Closely

We all know what are Default Arguments C++ are, but while playing with them,

I found 2 interesting things, many of you might know this but this will be new for freshers and learners.

 

1-) Look at the following code closely:
#include <iostream>

// something looks missing
void init(int =1, int =2, int =3);

int main()
{
    init();
    return 0;
}

void init(int a, int b, int c)
{
    std::cout << a << ' ' << b << ' ' << c;
}

 

If you closely observe function prototype then it looks like an error but it isn’t actually.
Variable names can be omitted in default arguments.
2-) Predict output of the following Code:
#include <iostream>
void init(int a=1, int b=2, int c=3);

int main()
{
    init();
    return 0;
}
void init(int a=1, int b=2, int c=3)
{
    std::cout << a << ' ' << b << ' ' << c;
}

 

The above program looks correct at first glance but will fail in compilation. If function uses default arguments then default arguments can’t be written in both function declaration & definition. It should only be in declaration, not in definition.

Correct version is:
#include <iostream>
void init(int a=1, int b=2, int c=3);
int main()
{
    init(); // It is fine
    return 0;
}
void init(int a,int b,int c)
{
    std::cout << a << ' ' << b << ' ' << c;
}

 

If you find this information useful share it!! or if anything incorrect then comment down.

Program to Convert Hexadecimal to Binary C++

How to convert Hexadecimal to Binary C++: To convert or change the hexadecimal number to binary number replace the each octal digits by a binary number using hexadecimal to binary chart. For example: We want to convert hexadecimal number 65B2 to binary. For this we will replace each hexadecimal digit to binary values using the … Read more