Beruflich Dokumente
Kultur Dokumente
PRACTICAL 1
Follow the steps below to write, compile, build and run your first C program:-
3. Create a source file and add to the project: Right-click Source Files in
Solution Explorer Window. Select Add → Add New Item. Choose C++ File
(.cpp) for Templates. Type a Name (hello.c) for the file (you must explicitly
type .c after the file name to create a C source file otherwise a C++ source file
will be created). Click Open button.
#include <stdio.h>
printf("Hello World!\n");
return 0;
} /* main */
Note: Go to the physical location of the project file folder and open the
folder. Find out what files are generated after the compilation.
6. Build the program (Linking program with library used): Select Build →
Build Practical1.
1. You should get the following message in the Output Build Window at the
bottom if you do not have any linking errors:
Build: 1 succeeded, 0 failed, 0 skipped
2. If you have errors or warning, the errors and warning description will be
shown in the task list windows. You need to correct the errors and warning
first before repeat step 5.
Note 1: Go to the physical location of the project file folder and open the
folder. Find out what files are generated after build.
Note 2: Try to find out the difference between Build and Rebuild and what the
Clean function will do.
1. Remove and save the current source file and add new source file to
the same project file:
i) Select File → Save hello.c As to save a copy of the source file in other
location.
ii) Right-click hello.c under Source Files in the Solution Explorer Window
and select Remove. (Remove will remove the source file from the project but not from the
folder)
iii) To start a second program, repeat steps 3 to 7 in the same project file
or,
Note: Each project file can only have one main program and more than one
source file. When you want to run your program in another computer, should you
copy the whole project file or just the source file?
Part B: Writing program using Visual C++ .NET
Try the program samples given below using the Visual C++ .NET. Follow the steps above
to write, compile, build and run the programs.
1. /* A first program in C */
#include <stdio.h>
int main( void )
{
printf( "Welcome to C!\n" );
return 0;
}
4. /* Addition program */
#include <stdio.h>
int main()
{
int integer1, integer2, sum; /* declaration */
if ( num1 == num2 )
printf( "%d is equal to %d\n", num1, num2 );
if ( num1 != num2 )
printf( " %d is not equal to %d\n ", num1, num2 );
if ( num1 < num2 )
printf( "%d is less than %d\n", num1, num2 );
if ( num1 > num2 )
printf( "%d is greater than %d\n", num1, num2 );
if ( num1 <= num2 )
printf( "%d is less than or equal to %d\n", num1, num2 );
if ( num1 >= num2 )
printf( "%d is greater than or equal to %d\n", num1, num2 );
Part C
5. Describe the three tools that a programmer may use to develop a program solution.