Back to Top

PCSX2 FPS Limit Fix

Fix the frame-limiting issues in PCSX2

Complete Hanbook for Minecraft Factions

Rise to new heights on your server, by reading and following this easy guide. Let everyone fear you and respect you at the same time.

Sunday, 5 April 2015

Begginer's Guide to C++- Chapter 3: Selection Statements

Its time for the 3rd chapter. I hope you have understood the basics and were able to write your first program and had no trouble doing all the practice questions. In this chapter, we will learn to specify conditions on the statements that are being executed.


Learnt in previous chapter:
  1. Header files
  2. void main()
  3. Input/Output
  4. Your first program


if statement:
if specifies the condition under which a block of code should be executed. Understand this as "If this then what to do?" statement.
Syntax-
if(condition)
     {Your favorite code;
      }
But what if you want to specify more than one condition, you can use else statement.
Syntax-
if(condition 1)
     {First code;
      }
else if(condition 2)
     {Second code;
      }
else
     {Third code;         // consider else as a default statement, if no condition is specified, else block will be executed, you can skip this "else" block entirely if you wish.
      }
Code continues;


Eg- If I want to display "excellent" if x=1, "good" if x=2 and "OK" on any other value of x, we will write the following code.
if(x==1)             // Pay attention, I have written x==1, remember I told you about an == operator, well this is how you use it to check values.
{cout<<"Excellent ";
}
else if(x==2)
{cout<<" Good ";
}
else
{cout<<"OK";
}
cout<<" Can I get a +1 :-)"; //Execution resumes here, after 1 of the blocks above have been executed.


switch statement:
switch statement is also like a if, but it is just a bit different.
Syntax -
switch (variable name)                                  // Should only be an int or a char
{case 1:Your favorite code;               //For char, you can write case ‘a’ instead of case 1  break;
case 2:Code 2;
break;
default: default code;
}


Eg - If I want to write the previous example in switch statement,
switch(x)
{case 1:cout<<”Excellent”;
break;
case 2:cout<<”Good”;
   break;
default: cout<<”O.K.”
}


You will now want to ask me that how will you be able to check for inequalities or ranges in switch statement, the answer is that you can’t. It only checks the value for a constant, in short ranges are not allowed, in switch, for ranges you NEED to use if statement.


You can make menu driven programs from these statements, by creating a dummy variable, say int choice; and storing user choice in it, and then checking it for the corresponding value.
Eg- if I want to make a program with a menu like this-


What do you want to do?
  1. Add
  2. Subtract
  3. Exit


I can make the user enter the choice in a variable, and use it in switch case to execute that specific code. Now, let us proceed with the questions. But first, I want to know your opinion on this, some programmers have said that what I am currently teaching is extremely basic (Which according to me should be, as you all are beginners), so I have decided to upload a specific sequence of chapters which will have extra information, only for those who are interested, please let me know how you feel about it, by commenting below.


Practice Questions:


Q1- Write a program that takes 2 numbers, and a character like ‘+’, ‘-’, ‘*’, ‘/’, and does the appropriate calculation. Do this using-
i. if statement
ii. switch statement


Q2- Make a menu-driven program, that calculates the area of a triangle, or a circle, or a square, as selected by the user.

Thursday, 2 April 2015

C++ Solutions: Chapter 2

Here is the code for Q4 in chapter 2

1) By using 3 variables-

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b,temp;
cout<<”Enter a and b”;
cin>>a>>b;
temp=a;
a=b;
b=temp;
}

2) By using 2 variables-

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b,temp;
cout<<”Enter a and b”;
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
}

Smash +1, if you solved it before this post! Lets see how many were able to do so!!

Wednesday, 1 April 2015

Begginer's Guide to C++- Chapter 2: Your First Program

A short one, but I promise, this is even more exciting than the previous one! You will make your first ever program! So without further discussions, let us head straight on to the tutorial.


Learnt in Previous Chapter:
  1. Variables, datatypes, operators
  2. Special Characters
  3. Initializing a variable
  4. Comments


Header Files:
Header files are files that contain specific functions, that perform special tasks. To include a specific header file, follow this syntax:
#include<headerfile name>
This line goes when you start writing a program.


Some important header files-
I will only describe the ones that you may need right now. To know about more function, write the name of the header file in C++ and right click to open up the help interface, it will have the names of all functions available.
  1. iostream.h -
    1. It contains all input output functions I will soon describe about. So including this file is important in your programs for now.
  2. conio.h -
    1. clrscr() - Clears the output screen.
    2. getch() - Waits for the user to enter a single character.


Taking input/Giving output:
  1. cin>> - This is used to get input from the user.
Syntax - cin>>variable name;
  1. cout<< - This is used to display the value of a variable or expression.
Syntax - cout<<variable name/expression;
You can also get input of more than 2 variables by cin>>a>>b>>c; similarly, you can display 2 variables/expressions by cout<<a<<b<<a+c;


Eg - If you want to display, “Yay, this guide is great” on the user screen”, you can write -
cout<<”Yay, this guide is great”;
       If you want to display the value of a variable a,
cout<<”The value of a is ”<<a;


void main():
All your code for the program will go below void main() line in {} -
Eg- void main()
{int x;
char y;
}


We are now ready to write our very first program, it is easy ain’t it? I have solved this one for you, so that you get an approximate idea of how statements are to be used. So let’s get started then.


Q- Write a program to add 2 variables.
Ans-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();                       //Clears the output screen
int x,y;
cout<<”Enter first number \n”;
cin>>x;
cout<<”Enter second number \n”;
cin>>y;
cout<<”The sum is ”<<x+y;//Alternatively, you can store x+y in another variable and can display it.
getch();                                //Waits for a character input before program termination*
}


*We need to use getch(), otherwise the program will terminate even before you see the output. You can try it yourself!


Questions for practice-
Q1 - Write a program to find the area of a circle, whose radius is given by the user.
Q2 - Write a program to enter marks in 3 subjects and calculate total and percentage and print them on screen. Assume that the marks are out of 100.
Q3 - Write a program to calculate simple interest. Principal value, time and rate are entered by the user.
Most important question-
Q4 - Write a program to SWAP the values of 2 variables. Eg- if initially a=10 and b=20, after the program is executed, a=20 and b=10. You are permitted to use-
  1. 3 variables
  2. 2 variables.


Monday, 30 March 2015

Begginer's Guide to C++- Chapter 1: Introduction to C++

This is the first chapter to a long upcoming series, aimed at making you all learn C++, in quite an easy and fun way. You will be able to learn almost all concepts, without getting tired or bored.

We will be using Turbo C++ compiler for the proceedings. You can search for this "Turbo C++ by Neutron", it will get you to a ready to install package. Also, some programmers will say that the conventions, along with the compiler that I use are outdated, and programming has become much more liberal, but I think that developing your skills on any compiler is fine and, you will learn to modify it, to suit other compilers. What is important is to learn to think like a programmer and break your objective into smaller targets/modules. Through my guide, you will learn just that!

C++ is a case-sensitive language, i.e. the words “doctor”,  “Doctor” and “DoCtOr” will be recognised as different by the compiler, so make sure you keep that in mind.

Basic Terminologies:
  1. Keyword: These are the commands that the compiler understands. Thus these are special words that make the compiler do certain things.
  2. Variable/Identifier: These are storage locations, eg. x=5, where x is called the variable (just like mathematics).
  3. Operator: +,-,*,/ etc. Nothing worthy to explain about them, they do what their symbol suggests.
  4. Datatypes: These are a way to specify the kind of variable you are making. Eg- int - integer, char - character.

Rules for naming variables:
  1. It should not be a keyword.
  2. It should not have any special character like ' ', '*', etc. However, '_' is allowed while naming.
  3. The name should not begin with a number.

Operators: The following operators are available in C++,
Algebraic Operators:
1. +,-,*,/...
2. % - It finds the remainder from 2 numbers. Eg- 3%2 will give answer as 1.
      32%10 will give answer as 2.
Conditional/Relational Operators: Used to check conditions.
3. <,>,<=,>=...
4. == - Used to check equality. Consider this statement as "Is this equal?". If you write x==3, you are asking " Is x equal to 3?". I will elaborate on this later, when its use comes up.
Logical Operators:
5. && - And operator, used to join 2 statements with "and". It is just like the usage in English - "I want to eat mangoes and apples." Here we need both apples and mangoes to be given, in order for me to eat them.
6. || - Or operator, used to join 2 statements with "or". It is also used similar to the way we use it normally - "I want to eat mangoes or apples". Here we need at least an apple it a mango, or even both for me to eat them.
7. ! - Not operator, negates the current input. Eg- != will check if two given values are not equal.
Increment and Decrement Operators:
8. ++ - Adds 1 to the variable's value. Eg- If a variable p is equal to 10, p++ will make it equal to 11.  You can write it both as p++ and ++p, it does not matter.
9. -- - Similar to the above operator, but instead subtracts 1 from variable's value.

Datatypes: Datatypes are of the following types:
  1. int- Used to define integer type variables. Range- -32768 to 32767.
Syntax- int variablename;
  1. float- It is used to define a variable with decimal values. Eg- 10.43. Range- 3.4E +/- 38.
Syntax- float variablename;
  1. double- It is similar to float, but it has a greater range. Range- 1.7E +/- 308.
Syntax- double variablename;
  1. char- It declares a character type variable. Characters are enclosed in ‘’ (Single quotes), and are also represented by ASCII Codes. ASCII codes range from - -128 to 127.
Syntax- char variablename;
  1. void- It denotes an empty set of values. I will explain it later. No variable of this type can be declared.

Special Characters: There are some characters that represent a special meaning. Some are as follow -
  • /n - New Line
  • /t - Tab
  • /a - CPU beep sound
  • /' - Prints '
  • /" - Prints "
                            
Rules for variable declaration:
Syntax:
datatype variablename1,variablename2;
You can also initialize a variable by a value while declaring it.
Eg.- int x=10; (initializes an integer variable and designates its value as 10)
There is one rule of thumb, that you must always remember- You can initialize 1 and only 1 variable while defining it. This means you can provide value to only 1 variable while declaring.
Eg- int x=10,y=20;   is invalid
      int x=10,y;          is valid
      int x=y=10;         is invalid
We always write a=b+c; to store the value of b+c in a. b+c=a is wrong, and the compiler will report an error. Eg- It is always "Tom plays a guitar" rather than "Guitar plays a Tom".



Comments:
Comments help in noting down what statement serves what purpose. They are of two types-
  1. Single Line - For writing a single line comment, first put a “//” and then write the comment. Eg- int x=10; //Initializing x
  2. Multiline - Multiline comments begin by “/*” and end at “*/”.
Eg- /* Hey, howdy?
This is a multi-line comment
I hope you understood the concept*/

So friends, I take my leave here. Please go over the article again, and try to memorize the whole thing because these are the most basic and fundamental concepts in C++, and you will need them at every step.