Assignment No. 1
Deadline
Your assignment must be uploaded/submitted at or before 3rd March 2003.
Uploading instructions
Please view the assignment submission process document provided to you by the Virtual University to upload the assignment.
Rules for Marking
It should be clear that your assignment will not get any credit if:
o The assignment is submitted after due date.
o The submitted assignment does not compile or run.
o The assignment is copied.
Objective
The objective of this assignment is to provide an on hand experience of:
o Writing and editing a C program
o Saving the C program
o Compiling your C program
o Executing the program
Further more, after the completion of this assignment you will have sufficient knowledge of the essential formatting characters and mathematical computing in C language.
Printing Special Characters
C provides a facility for outputting non-printing characters as well. These characters are used in order to get formatted outputs following special characters are very important:
‘\n’: This is called a new line character; it is used whenever there is a need to go to the beginning of next line e.g. to print the number of students on a new line following code is needed
NoStuds = 135 ;
cout << “Number of students is” ;
cout << ’\n’ ;
cout << NoStuds ;
Output
Number of students is
135
‘\t’: This is called a tab character; it is used to place a screen cursor on the next tab stop. e.g. to print the average age of all the students in class 5, 6 and 7.
int ClassFive = 10 ;
int ClassSix = 12 ;
int ClassSeven = 14 ;
cout << “Average age of students of class 5,6 and 7 is ” ;
cout << ’\t’<< ClassFive << ’\t’<< ClassSix << ’\t’ << ClassSeven ;
Output
Average age of students of class 5, 6 and 7 is 10 12 14
Developing / Solving Equations in C
We can develop or solve any kind of expression or formula in C. We can easily convert any given formula into C syntax. For example, the formula of calculating the area of a rectangle is:
Area of Rectangle = Length of the Rectangle x Width of the Rectangle
In C we can convert it with the following syntax:
areaOfRectangle = lengthOfRectangle * widthOfRectangle ;
Assignment
Write a small C program to calculate and display the area of a rectangle using the formula mentioned in the example.
Your program should:
§ Have two variables to hold the values of length and width respectively.
§ A variable to hold the area calculated for the rectangle.
§ Should input the value of height and width from the user
§ Print the length and width on a single line separated by tabs.
§ Print the area calculated on the next line having a tab after the statement.
Sample Output
Please enter the length of the rectangle: 12
Please enter the width of the rectangle: 18
Length of the rectangle: 12 Width of the rectangle: 18
The area of the rectangle is: 216
Important Note
You can improve your assignment by
· making the variable names self–explanatory
· commenting the code properly
· indenting the code properly for making it more understandable
Submit ONLY the .cpp file as your assignment.