Skip to main content

Posts

What are the characteristics of a good program in C++

The program should be written in a good style so that it is understandable to a reader. A good program is efficient in solving the given program.  Here are some of the characteristics of a good program : Effective and Efficient  User Friendly  Self-Documenting Code  Reliable  Portable  I.  Effective and Efficient The program produces correct results and works faster, taking into account of the memory constraints.  II.  User Friendly The user should not be concerned about inside the program, a program should work with the user by understandable messages and user work should be very low. The user should only be responsible to provide input the rest of the program should do.  III.  Self-Documenting Code A good program must be self-documented. The source code uses meaningful names for variables, subprograms and other constants.  IV.  Reliable The program must be able to handle unexpected situations like wrong data or no data, it should display a proper message or error message when dealin
Recent posts

C++ Program to determine whether an input Year is Leap Year or not

In C++ programming we can write code to check whether a year is a leap year or not. Let's look at the code to input the year and check if it is a leap year or not.  Leap year C++ Program to determine whether an input Year is Leap Year or not #include <stdio.h> int main() {    int year;    printf("Enter a year: ");    scanf("%d", &year);    // leap year if perfectly divisible by 400    if (year % 400 == 0) {       printf("%d is a leap year.", year);    }    // not a leap year if divisible by 100    // but not divisible by 400    else if (year % 100 == 0) {       printf("%d is not a leap year.", year);    }    // leap year if not divisible by 100    // but divisible by 4    else if (year % 4 == 0) {       printf("%d is a leap year.", year);    }    // all other years are not leap years    else {       printf("%d is not a leap year.", year);    }    return 0; }   The output of the Code  C++ Program to determine whet

What is Dynamic Memory Allocation in C++ Program

In the computer world, anything that is processed be it an instruction or any data first needs to be loaded and located in internal memory.  In C++ programs also any data that is processed while executing the program is held in the internal memory.  What is Dynamic Memory Allocation? Dynamic Memory allocation means that the memory that will be used during the program is not known beforehand and is allocated dynamically and on the go. It is allocated during the runtime as and when required by the program. In C++ there are two operators used in dynamic memory allocation  1. New  2. Delete New operator in dynamic memory allocation The new operator in C++ is used to create objects of all types. The new operator will allocate memory of the size of the data type specified in the program.  For Example iptr = new int ;  Storing initial values will allocate needed amount of memory from the free store to hold the value of the specified data-type and store the starting address of the newly alloca

C++ Program to input number of week's days and convert to equivalent name of day of the week

In C++ Program, we can write a code to input the number of week's days and convert it to the equivalent name of day of the week This is done by using the switch selection statement in C++ if you want to learn about the selection statements read it here, What are Selection Statements in C++  . Let's look at the code  to input the number of week's days and convert it to the equivalent name of day of the week #include <iostream.h> using namespace std ; int main ()  { int dow ; cout <<"Enter number of week's day(1-7) : " ;  cin >> dow;  switch (dow)  { case 1 : cout<< "\n" <<"Sunday" ; break ;  case 2 : cout<< "\n" <<"Monday" ; break ;  case 3 : cout<< "\n" <<"Tuesday" ; break ;  case 4 : cout<< "\n" <<"Wednesday" ; break ;  case 5 : cout<< "\n" <<"Friday" ; break ; case 6 : cout<< &

What are selection statements in C++ ? If and Switch

There are several statements that we can use in C++ programming that help in choosing a set of instructions for using the code depending upon an expression truth value.  What are Selection Statements in C++? As mentioned above there are several statements that we can use to choose a set of pre-defined instructions within a program in any section of the program as per the need. These are called selection statements in C++  In C++ Program there are two types of Selection statements  1. If  2. Switch  The If Statement of C++ To understand "if statement" let's look at an example.  Example - If you have 10 rupees then you can buy the chocolate.  Here, there is a condition in buying chocolate, if you have 10 rupees then only you can buy it.  This shows that the If is a condition which can be true or false, If it is false it won't be executed, in this example, if you don't have 10 rupees i.e. the condition is false you cant buy the chocolate.  So, If statement checks for

C++ Program to calculate the factorial of an integer

In C++ program you can write a program to calculate the factorial of an integer . Let's look at the code to calculate the factorial of an integer.  #include <iostream> using namespace std ; int main ()  { int i, num, fact=1 ; cout <<"\n Enter integer" ; cin>> num; i = num ;  while (num)  { fact *=num ; --num ; } cout<< "The factorial of " << i ; cout<<"is" << fact <<"\n" ; return 0 ;  } The output of the C++ Code  C++ Program to calculate the factorial of an integer

What is iostream.h in C++ Programing Language ?

In C++ programing language, all header files end with .H extension. In standard C++, all devices are accessed and used as a file.  One such header file is iostream.h in C++ programming language. In this, all input and output devices are treated as files.  Let's quickly look at what are the input and output devices mean in C++ program.  Standard Input Device - Keyboard  Standard Output Device   - Monitor  Standard Error Device - Screen or monitor In C++, input and output are not defined within, and are implemented with the help of a component of the C++ standard library which is I/O library.  A file is read simply as a stream of bytes at the lowest level. But at a user level, a file consists of possibly mixed data types which can be characters, arithmetic values class, objects etc.  What are the predefined streams in I/O Library? As discussed above there are input, output and error library in c++, they have some predefined streams objects as well which are used in the code. Let'