Lab 1
Lab 1
Lab 1
Theory:
The Development Environment - Integrated Development Environment (IDE):
The C compiler has its own built-in text editor. You may also use a commercial text editor or
word processor that can produce text files. The important thing is that whatever you write your
program in, it must save simple, plain-text files, with no word processing commands embedded
in the text. The files you create with your editor are called source files, and for
C++ they typically are named with the extension .CPP, .CP, or .C.
The C Developing Environment, also called as Programmers’ Platform, is a screen display with
windows and pull-down menus. Code of the program, error messages and other information are
displayed in separate windows. The menus may be used to invoke the operations necessary to
develop the program, debug and execute the program.
Writing a Program
When the Edit window is active, the program may be typed. Use the certain key combinations to
perform specific edit functions.
Saving a Program
To save the program, select save command from the file menu. This function can also be
performed by pressing the [CTRL+S]. A dialog box will appear asking for the path and name of
the file. Provide an appropriate and unique file name. You can save the program after compiling
too but saving it before compilation is more appropriate.
Project/Make
Before compiling and linking a file, a part of the IDE called Project/Make checks the time and
date on the file you are going to compile.
Executing a Program
If the program is compiled and linked without errors, the program is executed by selecting
Run from the Run Menu or by pressing the F10 key.
Correcting Errors
If the compiler recognizes some error, it will let you know through the Compiler window.
You’ll see that the number of errors is not listed as 0, and the word “Error” appears instead of the
word “Success” at the bottom of the window. The errors are to be removed by returning to the
edit window. Usually these errors are a result of a typing mistake. The compiler will not only tell
you what you did wrong; they’ll point you to the exact place in your code where you made the
mistake.
Exiting IDE
An Edit window may be closed in a number of different ways. You can click on the small square
in the upper left corner, you can select close from the window menu, or you can press the
[ALT+F4] combination.
Operators
There are various types of operators that may be placed in three categories:
Basic: + - * / %
Assignment: = += -= *= /= %=
(++, - - may also be considered as assignment operators)
Relational: < > <= >= == !=
Escape Sequences
Escape Sequence causes the program to escape from the normal interpretation of a string, so that
the next character is recognized as having a special meaning. The back slash “\” character is
called the Escape Character”. The escape sequence includes the following:
\n => new line
\b => back space
\r => carriage return
\” => double quotations
Examples:
Lab Tasks
1- Write a program to calculate the Area ( A= π r2 ) and circumference of a circle (C=2 π r),
where r = radius is taken as input and is declared as a constant. The precision of should be the
number of characters in your name. Display the result to 4 decimal places.
2- Write single C ++ statement to output the following on the screen:
My name is “Your Name”
And roll number is “Your_roll_no”
I am a student of “Your Department”
3- Write a program that perform basic arithmetic operations by getting values from User.
4- Write a program that accept value from user and display its square and cube without using
predefined functions?