Sie sind auf Seite 1von 4

UCCD 1003

PROGRAMMING CONCEPTS AND DESIGN

PRACTICAL 1

Part A: Introduction to Visual C++ .NET in Visual Studio .NET Environment

Follow the steps below to write, compile, build and run your first C program:-

1. Launch Visual Studio .NET: Select Start → All Programs → Microsoft


Visual Studio .NET 2003 → Microsoft Visual Studio .NET 2003.

2. Create a project: Select File → New → Project. Choose Visual C++


Projects for Project Types and Empty Project (.NET) for Templates. Type a
Name (Practical1) for the project and choose a Location (e.g. click Browse and
choose Desktop). Click OK button.

Note: Three folders will be created when Empty Project is chosen:


Source File Folder: To store all .c files.
Header File Folder: To store all .h files.
Resource File Folder: To store all miscellaneous files such as .txt, .jpeg,
.gif, etc.

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.

4. Type a program, for example the following program:

#include <stdio.h>

int main (void)


{
/* Statements */

printf("Hello World!\n");

return 0;
} /* main */

5. Compile the program (Check syntax error): Select Build → Compile


1. You should get the following message in the Output Build Window at the
bottom if you do not have any errors:
Build: 1 succeeded, 0 failed, 0 skipped
2. If you have syntax errors, the errors description will be shown in the task list
windows. You need to correct the errors first and repeat step 5.

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.

7. Execute the program: Select Debug → Start Without Debugging. A


console window will display the result. Press any key to close the window.

8. To write, compile, build and execute a new program, either:

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,

2. Start a new program in a new project files:


i) Right-Click on the Solution and choose Add → New Project.
ii) Choose Visual C++ Project for Project Types and Empty Project
(.NET) for Project Template and provide a name for the project.
iii) Right-Click on the new Project File and select Set As StartUp
Project before continue to next step.
iv) Repeat step 3 to 7 to write a new program.

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;
}

2. /* Printing on one line with two printf statements */


#include <stdio.h>
int main()
{
printf( "Welcome " );
printf( "to C!\n" );
return 0;
}

3. /* Printing multiple lines with a single printf */


#include <stdio.h>
int main()
{
printf( "Welcome\nto\nC!\n" );
return 0;
}

4. /* Addition program */
#include <stdio.h>
int main()
{
int integer1, integer2, sum; /* declaration */

printf( "Enter first integer\n" ); /* prompt */


scanf( "%d", &integer1 ); /* read an integer */
printf( "Enter second integer\n" ); /* prompt */
scanf( "%d", &integer2 ); /* read an integer */
sum = integer1 + integer2; /* assignment of sum */
printf( "Sum is %d\n", sum ); /* print sum */

return 0; /* indicate that program ended successfully */


}
5. /* Using if statements, relational operators, and equality operators */
#include <stdio.h>
int main()
{
int num1, num2;

printf( "Enter two integers, and I will tell you\n" );


printf( "the relationships they satisfy: " );
scanf( "%d%d", &num1, &num2 ); /* read two integers */

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 );

return 0; /* indicate program ended successfully */


}

Part C

1. Describe each of the steps involve in building a C program.

2. What is the difference between a source program and an object module?

3. Describe the basic steps in the system development life cycle.

4. List the steps that a programmer follows in writing a program.

5. Describe the three tools that a programmer may use to develop a program solution.

Discussion: Why we need programming?

Das könnte Ihnen auch gefallen