Skip to main content

Posts

Showing posts from August, 2012

Function Prototype

Ok Now Lets Learn About Function Prototype  A Function Prototype  is a declaration of the function that tell the program about the type if the values returned by the function and the number and type if arguments  Hmm.. Hard to get Let Under stand Functon Prototype By Example :- (i) int   = return type  (ii)Sum = Name if the function  (iii) (int  n1, int n) ;  =  List of Arguments  (iv) ;    =   Every function Prototype is followed by a Semicolon.

Generating Random No.

This program tell you how to Generate a Random no. every time u run the program. #include<iostream.h> #include<conio.h> #include<stdlib.h> void main() { int rnum ,i ; for (i=0; i<=5; ++i) cout<<(rnum=rand() ) << endl; getch(); }; Now See here Rnum is used to get random number.  i<=5 it means that it will select from 1 to 5 number it self

Infinite looping

Ever wonder to make an infinite loop its easy to make print up to any number . So why don't make an infinite loop which can go very long for this just using the For command will work although some minor modification have to be done here :- for(j=0;j<=any number;++j) Instead of this we can use for(j=25 ;   Leaving this space empty* ;  --j ) *just leave the space don't write any thing there

To Check whether the given number is a palindrom or not

#include<iostream.h> #include<conio.h> void main() { int n, num,digit,rev=0; cout<<"\n Enter the number(max=20000):"; cin>>num; n=num; do { digit=max%10; rev=(rev*10)+digit; num=num\10; } while(num!=0); cout<<"The reverse of the number is:<<rev<<"\n; if(n==rev) cout<<"\n The Number is Palindrome"; else cout<<"\n The Number is not a Palindrom"; getch(); };

To calculate the factorial of an integer

#include<iostream.h> #include<conio.h> void main () { unsigned long i,num,fact=1; cout<<"Enter integer; cin>>num; i=num; while(num) { fact = fact*num; --num; } cout<<The Factorial of "<<"\t"<<i<<"\t"<<is<<"\t"<<fact<<"\n"; getch(); };

loops in coding

Say we wanted to write a program that asked the user how many times they wanted a phrase repeated .  in that case we will continuosly use the cout and printf statement ic cand c++ resp. so in this case the program will be very lengthy.....so to solve this problem  loop is used LOOP is the sequence of instruction that is continuously repeated untill a certain condition is reached loop is 3 types : 1. for loop 2. while loop 3. do-while loop in my next post i will describe all loop..... remember programming can be done only when you know its theory

Why it is important to write Comments

There are two reasons to write a comment: 1. to improve the readability or maintainability of the code; or 2. to provide text for a documentation tool. If you can’t do either of these, don’t write a comment. Experienced programmers prefer to read and understand code without the aid of comments. They know, from bitter experience, that the code is a more reliable guide to what the program actually does. However, you will sometimes come up with tricky code after thinking deeply about a problem and rejecting alternative solutions. In this case, it may help the maintenance programmer (who might be you, six months later) by explaining why you write the code in a particular way. The only realistic way of keeping documentation consistent with code is to write the documentation as part of the code and then extract it using a tool such as Doxygen .Note the use of Doxygen markup such as \b, \param, and \return . If you use a tool such as Doxygen, use it consistently: provide docum

Summary of file streams

The stream class hierarchy is quite large. For practical purposes, there are four useful kinds of stream: ifstream : input file stream ofstream : output file stream istringstream : input string stream ostringstream : output string stream We will discuss string streams later. For each of these kinds of stream, there is another with “w” in front (for example, wifstream). These are streams of “wide” (16–bit or Unicode) characters. File streams are opened by providing a file or path name. The name can be passed to the constructor or to the open method. When a file is no longer needed, the close method should be called to close it. The extract operator >> reads date from an input file. The insert operator << writes data to an output file. The right operand of an extractor must be a Lvalue. The right operand of an inserter is an Rvalue. The right operand of an extractor or inserter may also be a manipulator. Manipulators may extract or insert data, but they are

Counting

In everyday life, if we have N objects and want to identify them by numbers, we assign the numbers 1,2,3,. .., N to them. Another way to look at this is to say that the set of numbers forms a closed interval which we can write as either 1 ≤ i ≤ N or [1, N]. Programmers are different. Given N objects, they number them 0,1,2,. .., N−1. This set of numbers forms a semi-closed (or semi-open interval which we can write as either 0 ≤ i < N or [0, N). The advantages of semi-closed intervals include: • They reduce the risk of “off-by-one” or “fencepost” errors. To see why off-by-one errors are called “fencepost errors”, consider the length of a fence with N posts spaced 10 feet apart. The length of the fence is 10(N − 1) • The closed interval [M, N] has N −M +1 elements; the semi-closed interval [M, N) has N −M elements, which is easier to remember and calculate. • Semi-closed intervals are easier to join together. Compare [A, B), [B, C), [C, D),.. . to [A, B − 1], [B,C −

Compiling with gcc

Using gcc under unix or Linux is much easier: just enter gcc (or perhaps g++) followed by options and file names. For any but the most trivial projects, you will probably find it easier to write a make file. Just This Much will do i guess

Compiling with Visual C++ .NET

By default, VC++ tries to include all kinds of Microsoft junk. You can use this stuff if you want to, but the programs discussed in the course will be written in plain old vanilla C++. Use the following steps to create simple C++ programs: 1. Start VC++. 2. Select File/New/Project or press ctrl-shift-n. In the New Project window: (a) In the Project types: window, select Visual C++ Projects. (b) In the Templates: window, select Win32 Project. (c) In the Name: box, enter the name of your program. (d) In the Location: box, enter a path for your project. (e) In the Solution: box, you can enter the name of a directory for your project. It is probably better to say that you don’t want this option. (f) Click OK to finish this dialogue. VC++ will open an Application Wizard. 3. In the Application Wizard window: (a) Click Application Settings. (b) Under Application Type:, select Console application. (c) Under Additional Options:, check Empty Project. (d) Click Finish. 4. You

Understanding fclose

int fclose ( FILE * stream ); Close file Closes the file associated with the stream and disassociates it. All internal buffers associated with the stream are flushed: the content of any unwritten buffer is written and the content of any unread buffer is discarded. Even if the call fails, the stream passed as parameter will no longer be associated with the file. Parameters stream Pointer to a FILE object that specifies the stream to be closed. Return Value If the stream is successfully closed, a zero value is returned. On failure, EOF is returned. Example /* fclose example */ #include <stdio.h> int main () {   FILE * pFile;   pFile = fopen ("myfile.txt","wt");   fprintf (pFile, "fclose example");   fclose (pFile);   return 0; }

C++ for Engineers and Scientists

Now in its third edition, Bronson's C++ for Engineers and Scientists makes C++ accessible to first-level engineering students as C++ maintains its stronghold in engineering and scientific communities. The text continues to take a pragmatic approach that incorporates actual engineering and science problems for its applications and examples. Students begin with a foundation in procedural programming, moving into object-oriented concepts in the second half of the text. This new edition also offers new case studies and an expanded selection of examples from a variety of fields including thermodynamics, optics, and fluid mechanics.

C++ Software Engineer

A C++ Software Engineer is responsible for developing and/or implementing the new features to improve the existing programs and software. C++ is a general purpose language in computer programming. It is a middle level language that can be used for several purposes in the computer industry. C++ language may not always be the most preferred programming language, but there are many aspects of software programming that cannot be done with out the use of C++. When developing or improving computer systems engineers implement techniques of computer science, engineering, and mathematical analysis to produce the most optimal solution or innovation.

Program to Merge Two Double Linked List

#include<iostream> using namespace std; class Node { public: int data; Node *next; Node *prev; Node() { data=0; next=prev=NULL; } }; class Node1 { public: int data; Node1 *next; Node1 *prev; Node1() { data=0; next=prev=NULL; } }; class Node2 { public: int data; Node2 *next; Node2 *prev; Node2() { data=0; next=prev=NULL; } }; class DoublyLinkedList { private: Node *headNode, *tailnode; Node1 *headNode1, *tailNode1; Node2 *headNode2, *tailNode2; public: DoublyLinkedList() { headNode=tailNode=NULL; headNode1=tailNode1=NULL; headNode2=tailNode2=NULL; } void Insert();//Insert data into the two lists void Merge() ;//Merging two lists into one void Display();//Display only the merged list }; void DoublyLinkedList::Insert() { char option; //This section inserts elements into the nodes of the first list do { Node *newnode = new Node(); cin>>newnode->data; newnode->next=NULL; newnode->prev=NULL; if(headNode==

Balloon Shooting Games

Just to tell you  its a very hard program to make with out error # include "graphics.h" # include "conio.h" # include "stdio.h" # include "stdlib.h" # include "dos.h" #define ARROW_SIZE 7 #define BALLOON_SIZE 3 // Downloaded from www.indiaexam.in int flag_arrow=0,flag_balloon=1,count_arrow=6,count_balloon=10; void *balloon,*bow,*arrow,*burst; void *clear_balloon,*clear_burst; void draw_balloon(int ,int ); void draw_burst ( int x, int y ); void draw_bow(int x,int y); void draw_arrow(int x, int y); void shoot(int *x, int *y); int testkeys(); void fly(int *x, int *y); void start(); void main() { int gmode = DETECT, gdriver , area ; initgraph ( &gmode, &gdriver, "c:\tc\bgi\ " ) ; setbkcolor(1); start(); int maxx = getmaxx() ; int maxy = getmaxy() ; int p=400,q=300,m=100,n=100,x=m,y=n,key,score=0,finish=0,level=1,l_flag=1; char score1[5],ch,cnt_ball[5],char_level[2]; rectangle ( 0, 0, maxx

A program to make Resume

#include<fstream.h> #include<string.h> #include<stdio.h> #include<conio.h> #include<process.h> int main() { char name[30],file[30],*blank=”.html”; char temp[200],ch; int num=0,len,i,line=1; cout<<”Enter Name Of The Database : “; gets(name); strcpy(file,name); strcat(file,blank); ofstream fout(file); if(!fout) { cout<<” Error In Making Of A File :”; exit(1); } fout<<”<html> “; fout<<”<blockqoute>”; fout<<”<center> “; fout<<”<b><h1><u>”<<”CURRICULAM VITAE”<<”</h1></b></u> “; fout<<”</center> “; cout<<” Enter Your Name : “; gets(temp); strcpy(name,temp); fout<<”<br><h2>”<<temp<<”<br> “; cout<<” Enter Your Address : “; gets(temp); len=strlen(temp); for(i=0;i<len;i++) { ch=temp[i]; if(ch==’ ‘) { num++; if(num==3) { fout<<”<br>”; num=0;

My Program Always Gets Error

Do you got the same problem making a program from any book and getting error. Here is a way to void those error or say not to make those error 1. Never full Copy the coding in the book make your on logic 2. Watch out for the Void Main and Int main. 3. if making a class most book just give the concept as a small program which always give error so watch those Just this much and u will find your error much less

Vector functions

vector vect( float X, float Y, float Z ) Creates a new vector with the given components. float VSize( vector A ) Returns the euclidean size of the vector (the square root of the sum of the components squared). vector Normal( vector A ) Returns a vector of size 1.0, facing in the direction of the specified vector. Invert( out vector X, out vector Y, out vector Z ) Inverts a coordinate system specified by three axis vectors. vector VRand() Returns a uniformly distributed random vector. vector MirrorVectorByNormal( vector Vect, vector Normal ) Mirrors a vector about a specified normal vector.

Floating point functions

float Abs( float A ) Returns the absolute value of the number. float Sin( float A ) Returns the sine of the number expressed in radians. float Cos( float A ) Returns the cosine of the number expressed in radians. float Tan( float A ) Returns the tangent of the number expressed in radians. float ASin( float A ) Returns the inverse sine of the number expressed in radians. float ACos( float A ) Returns the inverse cosine of the number expressed in radians. float Atan( float A ) Returns the inverse tangent of the number expressed in radians. float Exp( float A ) Returns the constant "e" raised to the power of A. float Loge( float A ) Returns the log (to the base "e") of A. float Sqrt( float A ) Returns the square root of A. float Square( float A ) Returns the square of A = A*A. float FRand() Returns a random number from 0.0 to 1.0. float FMin( float A, float B ) Returns the minimum of two numbers. float FMax( float A, float B )

Integer functions

int Rand( int Max ) Returns a random number from 0 to Max-1. int Min( int A, int B ) Returns the minimum of the two numbers. int Max( int A, int B ) Returns the maximum of the two numbers. int Clamp( int V, int A, int B ) Returns the first number clamped to the interval from A to B. Warning - Unlike the C or C++ equivalents, Min and Max work on integers. There is no warning for using them on floats - your numbers will just be silently rounded down! For floats, you need to use FMin and FMax.

Function Recursion

Function calls can be recursive. This means that the function can actually call itself. There are many situations where this is necessary or useful to cut down on the complexity of code needed to perform the desired action. For example, the following function computes the factorial of a number: // Function to compute the factorial of a number. function int Factorial( int Number ) { if( Number <= 0 )       return 1;     else       return Number * Factorial( Number - 1 ); }

Function Signature

The first line of the function declaration defines how the function is identified and addressed. This is called the function's signature . The signature specifies the name of the function, what values it can take in through function parameters, what (if any) return value it outputs, and any other pertinent information about the function through the use of function specifiers. The most basic function signature begins with the function keyword (special event functions begin event keyword instead). This is followed by the optional return type of the function, then the function name, and then the list of function parameters enclosed in parenthesis. From the example declaration above, the signature portion is: function byte GetTeam(Pawn PlayerPawn) This signature is for a function named GetTeam that takes in a reference to a Pawn and returns an byte value (which you can guess by the name of the function represents the team of the Pawn that was passed in). Functions can also

Any Idea what is Local classes

A local class is declared within a function definition. Declarations in a local class can only use type names, enumerations, static variables from the enclosing scope, as well as external variables and functions. For example: int x;                         // global variable void f()                       // function definition {       static int y;            // static variable y can be used by                                // local class       int x;                   // auto variable x cannot be used by                                // local class       extern int g();          // extern function g can be used by                                // local class       class local              // local class       {             int g() { return x; }      // error, local variable x                                        // cannot be used by g             int h() { return y; }      // valid,static variable y             int k() { return ::x; }    // valid, global x

Nested if and if-else statements

The if-else statement allows a choice to be made between two possible alternatives. Sometimes a choice must be made between more than two possibilities. For example the sign function in mathematics returns -1 if the argument is less than zero, returns +1 if the argument is greater than zero and returns zero if the argument is zero. The following C++ statement implements this function: if (x < 0)    sign = -1; else    if (x == 0)       sign = 0;    else       sign = 1; This is an if-else statement in which the statement following the else is itself an if-else statement. If x is less than zero then sign is set to -1, however if it is not less than zero the statement following the else is executed. In that case if x is equal to zero then sign is set to zero and otherwise it is set to 1.

WELCOME TO THE GREAT BHAVAN'S QUIZ COMPETITION !!!

Program Created By :- Arindam Bera   ------------------------------------------------------------------------------------------------------------- #include<iostream.h> #include<string.h>                                                                                        //header files #include<stdio.h> void main () { int aa=0,ab=0,ac=0,ad=0,ba=0,bb=0,bc=0,bd=0,ax,bx,ca=0,wa=0,pa=0,cb=0,wb=0,pb=0;                          //variables declared char x[100],a[100],b[100],y; abc: cout<<"******************************************************************************"<<endl; cout<<"             WELCOME TO THE GREAT BHAVAN'S QUIZ COMPETITION !!!               "<<endl;             //welcome note displayed cout<<"******************************************************************************"<<endl; cout<<endl; cout<<endl; cout<<" Enter the name of