Thursday, September 13, 2012

Capitalize First Letter Of Sentences

Compiler Used: TurboC
Language: C

This program demonstrates how to read file contents from c.txt, capitalize first letter of every sentence and then write it to d.txt.


//capitalize first letter of every sentence
//after every fullstop capitalize the first alphabet encountered
#include<stdio.h>
#include<conio.h>

void main(){
clrscr();
int cap=1;
char c;
FILE *fp1, *fp2;

fp1 = fopen("c.txt", "r");
fp2 = fopen("d.txt", "w");
while((c=getc(fp1))!=EOF){
if(c == '.'){
cap =1;
}
if(cap ==1 && c >=97 && c<=122){
c = c-32;
cap =0;
}
putc(c, fp2);
}
rewind(fp1);
while((c=getc(fp1))!=EOF){
 putchar(c);
}
printf("\n\n");
fclose(fp1);
fclose(fp2);
fp2 = fopen("d.txt", "r");
while((c=getc(fp2))!=EOF){
    putchar(c);
}
getch();
}

Here is what output looks like:

You can see contents of c.txt has been copied to d.txt and first letter of every sentence has been capitalized.

PS: Improvements/Suggestions/Comments on the program are welcome. I am sure there are better ways to do it.

Convert File Contents To Uppercase In C

Compiler Used: TurboC
Language: C

This program copies content from a.txt converts it into uppercase and writes it to file b.txt.


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

void main(){
clrscr();
char c;
FILE *fp1, *fp2;
fp1 = fopen("a.txt", "r");
fp2 = fopen("b.txt", "w");
while((c = getc(fp1))!=EOF){
//printf("%c", c);
//getch();
if(c>=97){
 c = c-32;
}
putc(c, fp2);
}
fclose(fp1);
fclose(fp2);
fp2 = fopen("b.txt", "r");
while((c=getc(fp2))!=EOF){
 putchar(c);
}
fclose(fp2);
getch();
}

PS: Comments/Suggestions/Improvements are welcome.

Copying From One File To Another In C

Compiler Used: TurboC
Language: C

This is a simple program to demonstrate file handling in C by copying contents of a.txt to b.txt and displaying on the screen.


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

void main(){
clrscr();
char c;
FILE *fp1, *fp2;

fp1 = fopen("a.txt", "r");
fp2 = fopen("b.txt", "w");
while((c = getc(fp1))!=EOF){
        putc(c, fp2);
}
fclose(fp1);
fclose(fp2);
fp2 = fopen("b.txt", "r");
while((c=getc(fp2))!=EOF){
        putchar(c);
}
fclose(fp2);
getch();
}

PS: The program can be made better in a lot of ways. Suggestions/Comments are welcome.

Sunday, September 9, 2012

Understanding The Switch Statement

Basic Syntax:

switch(some-expression){
case some-constant1:
/* some code*/
break;


case some-constant2:
/* some code*/
break;


default:
/*some code*/
break;
}

Now important points worth noting are:

  1. some-expression in the switch(some-expression) can be an expression, a constant or a variable
  2. In the cases within switch construct, some-constant are constant integer values. Floats and expressions are not allowed here
  3. break; is optional
  4. default case is also optional
Interesting cases arise when break; are not used. Look at the following example:



switch(1*3-1){
case 1:
printf("\nThis is case 1.");


case 2:
printf("\nThis is case 2.");


case 3:
printf("\nThis is case 3.");

default:
printf("\nThis is default case.");
}

If you run this the output is:

This is case 2.
This is case 3.
This is default case.

So you can see that switch goes directly to the case indicated by the value of some-expression and then keeps on executing statements until a break; is encountered or until the end of the construct.

PS 1: Compiler used is TurboC
PS 2: Corrections/Suggestions/Comments are welcome.

Wrong Input Through scanf, What Happens?

scanf does not assign the value entered in case of wrong input.

Go through the following lines of code:

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

void main(){
int x=100;
scanf("%d", &x);
printf("Value of x is = %d", x);
getch();
}

Now the scanf is supposed to scan an integer value. Take 2 cases where you input:
(i) 2
(ii) d (or any character)

In (i) printf prints Value of x is = 2.
In (ii) printf prints Value of x is = 100.

Note that when you give wrong input to scanf, it does not assign any value to x and so the previous value of x is retained.

PS1: Compiler used TurboC.
PS2: Corrections/Suggestions/Comments are welcome!

What Does printf & scanf return?

printf returns the number of characters it prints. 

Examples:
If you write an expression like:
x = printf("%s", "Muttley is awesome!"); or
y = printf("%d", 1111);
then, what does printf return to x and y?

x = 19 and y = 4.

scanf returns the number of items it scans. However it stops scanning as soon as you give wrong input.

Examples:
p = scanf("%d%d%d", &y, &z, &w);
r = scanf("%d%d", &y, &z);

If all inputs are correct in the expression for p then, 
p = 3. Similarly, r = 2.

Lets say you give wrong third input(may be you enter a character instead of int) in the expression for p, immediately scanf stops and returns the value 2 to p. If the first input is wrong then scanf will return 0 to p.

So we can say that scanf returns the number of items scanned before the first wrong input entered. 
(Reminds me of geometric distribution)

Thursday, September 6, 2012

Small q And BIG Q


Little Q is performance to specifications, i.e. the approach that is dominant in Six Sigma and ISO 9000.

Big Q is delivering what the customer wants and exceeding those expectations. It’s the difference between tactical quality management and strategic quality management.


Big Q arose out of the realization that managing for quality should not be limited to manufacturing companies and manufacturing processes, but should also include service companies and business processes. Quality managers and upper managers have most accepted the concept of Big Q, starting in the 1980s, and the trend has been growing ever since. Time has also shown that managers in technological areas and certain staff functions have traditionally been the most resistant to it.

Big Q takes the goals of more traditional, earlier modes of quality control management (“Little q”) and builds on them. For the purposes of better understanding, let’s look at it this way: In terms of products, for example, the content of Little q would be manufactured goods, while the content of Big Q would encompass all products, goods and services, whether for sale or not. In terms of processes, Little q focuses on those processes directly related to the manufacture of goods, while Big Q covers all processes.

It has been demonstrated that since the widespread adoption of the Big Q concept in the 1980s, recognition for quality within the corporate world has increased. Quality councils have sprung up more and more to nominate and select specific projects to be recognized for their quality achievements. The scope of these nominations has increased over time, and this has been attributed to the manner in which Big Q has broadened the notions of what constitutes quality management.

Big Q has become an integral component in the business world, and is without question here to stay. We just may not call it Big Q. Some may call it TQM, some Six Sigma and others just common sense.

PS: Source- juran.com

Who Is Customer & Types Of Customers


A customer is anyone who is impacted by the product or process. Customers may be external or internal.

EXTERNAL CUSTOMERS. These are impacted by the product but are not members of the company that produces the product. External customers include clients who buy the product, government regulatory bodies, and the public (which may be impacted due to unsafe products or damage to the environment).

INTERNAL CUSTOMERS. They are impacted by the product, and are also members of the company that produces the product. They are often called "customers" despite the fact that they are not customers in the dictionary sense, that is, they are not clients.

Saturday, September 1, 2012

Measures of Central Tendency

What does it measure of central tendency mean?

Measure of central tendency is a single value that attempts to describe a set of data by identifying the central value of that set of data.

Mean

When NOT to use mean?

Mean is susceptible to outliers. Which means it is effected by extremely high and extremely low values in the data. In such situations median is preferred over mean.

Another case is when the distribution is skewed. As the data becomes skewed the mean loses its ability to provide the best central location for the data as the skewed data is dragging it away from the typical value in the direction of the skew. In this case also median is preferred measure of central tendency.

Median

Median is a value that splits the data in two equal halves.
To calculate median arrange the data in ascending order then:
1. If the number of data (n) is odd then median is (n+1)/2th value.
2. If the number of data (n) is even, median is the average of n/2 and (n/2 + 1)th value.

Median is more resistant to outliers and skewed data than mean.
If data is non-normal then it is customary to use median instead of mean.

Mode
Mode is the most frequently occurring value in the data. Normally mode is used for categorical data.

The problem with mode is that it is not unique. In case of multi-modal data which mode represents the central tendency of data set becomes a difficult question.

Mode is also not suitable measure of central tendency in case of a continuous data, especially if the data set is not large. In such cases getting a clear mode becomes a problem.

Another case may arise when the most frequent data is far away from the rest of the data. In such case mode does not give a good measure of central tendency.

Summary of when to use mean, median , mode

Type of VariableBest measure of central tendency
NominalMode
OrdinalMedian
Interval/Ratio (not skewed)Mean
Interval/Ratio (skewed)Median


PS1: Source: Laerd Statistics: Mean, Mode, Median - Measures of Central Tendency
PS2: Corrections/Improvements/Comments are welcome.

Graphs, Frequency Distributions & Histograms For Displaying Data Distributions

Distribution
Distribution of variable describes what values the variable takes and how often it takes.

Bar Graph

Bar Graph shows the amount of data that belongs to each category in proportionally sized rectangular bars.
Data from categorical variables can be summarized using bar charts.

The following Bar Graph shows the Per Capita Net State Domestic Product at Current Prices (in Rupees) for 2010-11:

Data Source: Press Information Bureau, GOI, Per Capita Net State Domestic Product


Frequency Distribution

Wolfram MathWorld describes frequency distribution as "The tabulation of raw data obtained by dividing it into classes of some size and computing the number of data elements (or their fraction out of the total) falling within each pair of class boundaries."

Using Tally is a convenient and less error prone way to make frequency distribution tables.


Histogram
Data from quantitative variables are most commonly summarized using histograms. 

How To Draw Histograms

a. What are the number of observations (N) ? 
b. What is the range of the data? Range, R = H-L, H = highest value, L= least value. 
c. Use Sturge’s rule (k = 1+3.322LogN) to find the number of classes. 
d. Find the class width. cw = R/k. 
e. Make a frequency distribution of the data using the classes, [L,L+cw], [L+cw, L+2cw],... (use tally marks to count frequencies)
f. Draw the histogram.

Notes:
1. In order to avoid getting class width as fraction we can also use the formula 
cw = (R+w)/k where w is the least count of data. If that doesn't solve the problem then we may have to round off the class width.
2. To avoid any data point falling on boundaries of classes we can define classes as,
[L-w/2, L-w/2+cw], [L-w/2+cw, L-w/2+2cw],....
Again w, here is the least count of data.

PS: Improvements/Corrections/Comments are welcome.

Descriptive Vs Inferential Statistics

Descriptive Statistics
Collection, presentation and description of data by graphs, tables and numerical summaries such as averages, variances etc.

Inferential Statistics
Interpretation of data as well as drawing conclusions and making generalizations from the data for larger group of subjects.

Population
Entire group of individuals or subjects about which we want to gain information.

Sample
A subgroup of a population from which we obtain information in order to draw conclusions for the entire population.

Parameter
It is the numerical summary for the entire population. A parameter is unknown because the entire population cannot be studied. We use the information based on a sample to arrive at the value of population parameter. The process is inferential.

Statistic
It is the numerical summary obtained from real data or sample. We can actually observe statistics. The process is descriptive.


We can roughly understand the whole process as follows:

Sample → Descriptive Statistics(statistics) → Inferential Statistics(parameters) → Population

So we take a sample, we describe it using graphs and numerical summaries like averages, variances etc then we apply inferential statistics and make generalizations about the population.


PS: Any Improvements/Corrections/Comments are welcome.