Assignment
Assignment
ASSIGNMENT
SUBMITTED TO:
Sir Musadaq Fida (HOD)
BASIC STRUCTURE OF C++
PROGRAM:
#include <iostream>
#define PI 3.14159
int main() {
std::cout << "The area of the circle is " << area << std::endl;
return 0;
#include <iostream>
int main() {
#ifdef DEBUG
#else
#endif
return 0;
Example:
#include <iostream>
int main() {
// This code uses the `cout` object from the `iostream` header file.
cout << "Hello, world!" << endl;
return 0;
}
conio.h: The word “conio” stands for console input/output . The
conio.h header file contains functions for controlling the console
input and output. The clrscr() function clears the screen, and the
getch() function waits for the user to press a key and returns the
character.
Example:
// This program shows the working of the conio.h header file.
#include <iostream>
#include <conio.h>
int main() {
// This code uses the `clrscr()` function from the `conio.h` header file to clear the screen.
clrscr();
// This code uses the `getch()` function from the `conio.h` header file to wait for the user to
press a key.
char ch = getch();
// This code prints the character that the user pressed to the console.
std::cout << "You pressed the character " << ch << std::endl;
return 0;
}
#include <iostream>
#include <math.h>
int main() {
// Declare a variable to store the number.
double number = 16;
return 0;
}
string.h: This header file contains information about various
string function such as str.cpy() for copying a string, str.cmp() for
comparing strings , str.length() to returns the length of the string,
str.find() to find the first occurrence of a substring in the string,
str.uppercase() to converts the string to uppercase, str.lowercase()
to converts the string to lowercase etc. These functions are used for
manipulating strings.
Example:
// This program shows the working of the `string.h` header file.
#include <iostream>
#include <string>
using namespace std;
int main() {
// Create a string variable.
string str = "This is a string.";
return 0;
}
main() function:
The main function indicates the beginning of the C++ program.
When a C++ program is executed the control goes directly to the
main function and starts executing its statements. All C++
programs must have main functions if a C++ program does not
contain a main function it can be compiled successfully but cannot
be executed.
General-Syntax:
The general syntax of the main function is as follows:
In this syntax:
C++ STATEMENTS
A program statement is a
fundamental unit of any programming language. It is an
instruction for the computer to do something. The statements
of C++ program are written under the main () function
between the curly brackets { } the set of statement written
under the main function or any other user defined function is
known as body of the function.
Diagnostic Message:
Statement missing;
DEBUGGING IN C++
ERRORS IN C++
Different errors may arise in C++ program. Errors in the
program are called bugs. The process of finding and
removing bugs in a program is known as the Debugging.
1. SYNTAX ERROR:
The set of rules of a programming language
for writing statements of the computer program is known as the
syntax of the language the program statements are written strictly
according to these rules.
2. LOGICAL ERRORS:
3. RUNTIME ERRORS:
The errors that occur during the
execution of a program are called runtime errors or execution
errors. These types of errors may occurred due to the following
reasons:
When a program attempts to perform an illegal operation such
as division of a number by zero
If input data given to the program is not in a correct format
or input data file is not found in the specified path.
If hardware problem occur such as hard disc error or disc
full or printer etc.
When a run time error occurs the computers Jobs the execution
of the program and displays an error message.
PROGRAMS
PROGRAM NO 1: (Concept of integer overflow and under flow.)
PROGRAM NO 2:
Convert 2.5 miles into kilometers.
PROGRAM NO 3:
Write program that declare and initialize two variables of int data type.
PROGRAM NO 4:
Write a program that computes the volume of a cylinder.
l
PROGRAM NO 5:
Write a program that computes the area of a circle.
Program no: 6
D:
E:
F:
G:
H:
I:
J: