Concepts Of Programming Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

This assignment is based on the programming concepts and understanding the concepts of programming language syntax and program Design, Complier, Languages and Platform. In this assignment, we are learning using the control structures and functions and procedures. A C++ program is a collection of commands, which tell the computer to do "something". This collection of commands is usually called C++ source code, source code or just code. Commands are either "functions" or "keywords". Keywords are a basic building block of the language, while functions are, in fact, usually written in terms of simpler functions--you'll see this in our very first program, below. (Confused? Think of it a bit like an outline for a book; the outline might show every chapter in the book; each chapter might have its own outline, composed of sections. Each section might have its own outline, or it might have all of the details written up.) Thankfully, C++ provides a great many common functions and keywords that you can use. 

Data Types: - C/C++ language becomes powerful with the help of number of data types linked with it. Data types vary according to their use. Different compilers have different data types. Actually variable type depends on the data type. Data type is the description of nature of data either in numeric forms (integer or real) or in character form (single character or string).

Integer Data Type:- Integers are whole numbers with a machine dependent range of values. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.

Float Data Type:- Floating point number represents a real number with 6 digits precision. Floating point numbers are denoted by the keyword float.

Double Data Type:- These data types have very large floating data, so these are called large real number. These have double precision value.

Character Data Type:- A single character can be defined as a defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to char. While unsigned characters have values between 0 and 255, signed characters have values from -128 to 127.

The elements of an array are indexed from 0 to size-1. It is necessary to declare the size of an array before initialization. An array can be initializing by placing the elements of an array within the curly braces.

String:- Variables that can store non-numerical values that are longer than one single character are known as strings. The C++ language library provides support for strings through the standard string class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.

Structure:- A Structure can be defined as a collection or a group of variables that are referenced under one name. it is used to keep related information together. Here we use a 'struct' keyword to construct a structure.

Class:- A class can be defined as a group of objects which are similar or of the same kind. Here a keyword 'class' is used to construct a class. Here comes the concept of access specifiers which applies a kind of restriction on the data. There are three types of access specifiers namely public, protected and private.

3.) User Define Data Type:- In C language a user can define an identifier that represents an existing data type. The user defined data type identifier can later be used to declare variables. The general syntax is

typedef type identifier;

here type represents existing data type and 'identifier' refers to the 'row' name given to the data type.

The second type of user defined datatype is enumerated data type which is defined as follows.

Enum identifier {value1, value2 …. Value n};

The identifier is a user defined enumerated datatype which can be used to declare variables that have one of the values enclosed within the braces.

4.) Void Data Type:- Void or empty data types is used in the user define function or user defined sub-programs. These are used when the function sub-program returns nothing. Also it is used when a function or any sub-program have not any argument in it.

5.) Pointer Data Type:- Pointer data type are used to handle the data at their memory addresses.

Assignment 1(b):- Discuss the appropriate input/output statements and operators and show how you would use them.

Input/Output:- One of the essential operations performed in a C/C++ language programs is to provide input values to the program and output the data produced by the program to a standard output device. We can assign values to variable through assignment statements such as x = 5 a = 0; and so on. Another method is to use the Input then scanf which can be used to read data from a key board. For outputting results we have used extensively the function printf which sends results out to a terminal. There exists several functions in 'C/C++' language that can carry out input output operations. These functions are collectively known as standard Input/Output Library. Each program that uses standard input / out put function must contain the statement.

# include < stdio.h >

at the beginning.

Single character input output:

The basic operation done in input output is to read a character from the standard input device such as the keyboard and to output or writing it to the output unit usually the screen. The getchar function can be used to read a character from the standard input device. The scanf can also be used to achieve the function. The getchar has the following form.

Variable name = getchar:

Variable name is a valid 'C/C++' variable, that has been declared already and that possess the type char. The putchar function which in analogus to getchar function can be used for writing characters one at a time to the output terminal. The general form is

putchar (variable name);

String input and output:

The gets function relieves the string from standard input device while put S outputs the string to the standard output device. A strong is an array or set of characters. The function gets accepts the name of the string as a parameter, and fills the string with characters that are input from the keyboard till new line character is encountered. (That is till we press the enter key). All the end function gets appends a null terminator as must be done to any string and returns. The puts function displays the contents stored in its parameter on the standard screen.

The standard form of the gets function is

gets (str)

Here "str" is a string variable.

The standard form for the puts character is

puts (str)

Where str is a string variable.

Formatted Input For Scanf:

The formatted input refers to input data that has been arranged in a particular format. Input values are generally taken by using the scanf function. The scanf function hasthe general form.

Scanf ("control string", arg1, arg2, arg3 ………….argn);

The format field is specified by the control string and the arguments arg1, arg2; …………….argn specifies the address of location where address is to be stored.

The control string specifies the field format which includes format specifications and optional number specifying field width and the conversion character % and also blanks tabs and new lines. The Blanks tabs and new lines are ignored by compiler. The conversion character % is followed by the type of data that is to be assigned to variable of the assignment. The field width specifier is optional.

Programming Concepts 10

Some of the commonly used format specifiers are mentioned below:

%c - Print a character

%d - Print a Integer

%f - Print float value

%s - Print a string

%x - Print a hexadecimal integer (Unsigned) using lower case a - F

%X - Print a hexadecimal integer (Unsigned) using upper case A - F

%a - Print a unsigned integer.

%p - Print a pointer value

%hx - hex short

%lo - octal long

%ld - long

Operators:

An operator can be defined as a thing which is used to represent the operations or specific tasks and the objects of the operations are referred to as operands.

There are various types of operators:

1)     Arithmetic operators

2)     Logical operators

3)     Relational operators

4)     Increment and decrement operators

5)     Conditional operators

6)     Bitwise operators

Now we will look at these operator types one by one.

Arithmetic Operators:

C/C++ provides five basic arithmetic operators for calculations like : addition, subtraction, multiplication, division and remainder which are +, -, *, / and % respectively. All these operators are called binary operators as these require two operands or values.

Programming Concepts 11

Arithmetic operators are divided into two types:

Unary operators: acts on one operand only.

Binary operators: acts on two operands.

Logical Operators :

In this section we talks about the logical operators that refers to the ways in which the relationships can be connected. C/C++ provides three logical operators. These are :

Symbol

Name

&&

And

||

Or

!

Not

Relational Operators:

The relational operator determines the relation among different operands. C/C++ provides six relational operators for comparing numbers and characters. The following relational operators are:

symbol

Name

==

Comparison

<

Less than

<=

Less than or equal to

>

Greater than

>=

Greater than or equal to

!=

Not equal to

Increment & Decrement Operator:

Increment operator is denoted by ++ and decrement operator is denoted by -.

The operator ++ adds 1 to its operand and - operator subtracts 1 from the operand.

Conditional Operators :

Conditional operator stores a value depending upon the condition. This operator is ternary operator as it requires three operands.

General form is:

Expression1? expression2: expression3

Programming Concepts 12

If expression1 evaluates to true i.e. 1, then the value of the whole expression is the value of expression2, otherwise the value of whole expression is the value of expression3.

Bitwise Operators:

One of the powerful features of C/C++ is a set of bit manipulation operators. These permit the programmer to access and manipulate individual bits within a piece of data. The various bitwise operators are :

operator

meaning

~

One's complement

>>

Right shift

<<

Left shift

&

Bitwise AND

|

Bitwise OR

^

Bitwise XOR(exclusive OR)

Programming Concepts 13

Assignment 1(c):- Identify the appropriate selection and loop structures for the given task and show how you would use them.

Loop:- Loops in C are used to repeat a certain block of code a given amount of times. This is what computing is really all about. It saves the programmer time and coding. There are several loops as they are also referred to in C

For Loop: - For loops repeat a given number of times, so long as the criteria is true.

Syntax:-

for (variable initialization; condition; variable update)

{

Code to execute while the condition is true

}

While Loop:- While loops work: while this is true, keep repeating through the loop.

Syntax:-

while (condition )

{

Code to execute while the condition is true

}

Do While Loop: - A Do While loop is similar to a While loop, except that with a Do While loop, the program always loops through at least one time.

Syntax:-

do

{

} while (condition);

In the given problem we use the for loop and nested for loop the for loop is used to get the value from the user and the nested for loop is used to compare the value of two arrays.

Programming Concepts 14

Syntax for nested for loop:-

for (variable initialization; condition; variable update)

{

for (variable initialization; condition; variable update)

{

Code to execute while the condition is true

}

}

Programming Concepts 15

Assignment 1(d):- Write the complete program as per the standards.

Program:-

#include<iostream.h> //this header file is used for input/output functions

#include<conio.h> //this header file is used for clrscr () & getch () function

#include<stdlib.h> //this header file is used for exit function

Void main () //main function of program is begin

{

int p[20], q[20]; //declare the two arrays with size 20

int n,i,j; //declare three integer type variables

clrscr (); //clear the screen

cout<<"How Much Element You Want to Insert in the Array (<20) :";

cin>>n; //get the number of elements from user

for(i=0;i<n;i++) //begin for loop to get the element of p array

{

cout<<"\nEnter the "<<i+1<<" Element of P: ";

cin>>p[i]; //get the element of p array

} //end of for loop

for (i=0;i<n;i++) //begin for loop to get the element of q array

{

cout<<"\nEnter The "<<i+1<<" Element of Q: " ;

cin>>q[i]; //get the element of p array

} //end of for loop

for (i=0;i<n;i++) //begin the outer for loop

{

for(j=0;j<n;j++) //begin the inner for loop

{

if (p[i]==q[j]) //if elements of p & q array are same then

{

cout<<"\n"<<p[i]<<"Element Matched In P & Q Array";

getch (); //freeze the monitor

Programming Concepts 16

exit (0); //exit form program

}//end of if

} //end of inner for loop

} //end of outer for loop

cout<<"No Element Matched in P & Q Array"; //if no element matched then print message

getch(); //freeze the monitor

} //end of main function

Output:-

Programming Concepts 17

Assignment 2 (a):- Write a program to input the two Celsius values (start and end) and to produce the output exactly as shown with column headings and the temperature values aligned as shown using a function Convert (cels) which accepts a Celsius value and returns the equivalent Fahrenheit temperature.

Program:-

#include<iostream.h> //this header file is used for input/output functions

#include<conio.h> //this header file is used for the clrscr () and getch () functions

int start, end; //start, end two global variables are declared

float convert (int cel) //convert () is defined it is used for converting the Celsius to

Fahrenheit

{

float farh; //variable farh is declared as local

farh=1.8*cel+32; //converting Celsius to Fahrenheit

return (farh);

} //end of convert function

void main () //main function begin

{

clrscr (); //clear the screen

int i; // variable i is declared as local

float fahrenheit;

cout<<"\n Enter Celsius Start Value:"; //print message on screen

cin>>start; //get the starting Celsius from user

cout<<"\n Enter Celsius End Value:"; //print message on screen

cin>>end; //get the end value of Celsius from user

cout<<"\n"<<"Celsius"<<"\t"<<"Fahrenheit"; //print message

for (i=start;i<=end;i=i+10) //a for loop is begin

{

fahrenhei=cel_fah (i); //call the cel_fah() function

cout<<"\n"<<i<<"\t"<<fahrenhei; //print Fahrenheit on screen

} //end of for loop

getch (); //freeze the monitor

} //end of main

Programming Concepts 18

Output:-

Programming Concepts 19

Assignment 2(b):- Demonstrate the effect of scope and lifetime of variables in context to the above program.

Scope of a Variable: - The scope of a variable is the portion of the program where the variable is valid or "known". The variable can be declared as global or locally. The scope of global variable is occurs outside of all curly braces but the scope of local variable is limited within a curly brace. Now in the above program we declare two variables start and end as global so that these variables are visible in all the functions but we declare farh variable with in the convert function so the scope of farh variable is within the convert function we can not use the farh variable outside the convert function.

Lifetime of a Variable:- A variable's lifetime is the period of time during which that variable exists during execution. Some variables exist briefly. Some are repeatedly created and destroyed. Others exist for the entire execution of a program. An automatic variable's memory location is created when the block in which it is declared is entered. An automatic variable exists while the block is active, and then it is destroyed when the block is exited. Since a local variable is created when the block in which it is declared is entered and is destroyed when the block is left. For example in the above program memory location for farh variable is created when we call the covert function after execution the convert function memory of farh variable is destroy.

Programming Concepts 20

Assignment 2(c):-Discuss that how you can pass the data effectively between modules

In the above program we use the two modules one for converting the Celsius into Fahrenheit which accept the one argument as a Celsius and another module is main module from which the execution of the program is begin. In the main module we accept the two values from user starting value of Celsius and ending value of Celsius. After that we begin a for loop which help us to reach the starting value of Celsius to end by the difference of ten. In this we call the convert function by passing a argument as a Celsius which return the Fahrenheit corresponding to the Celsius. So we pass the data between modules by using the technique call by value means we pass a copy of the variable (Celsius) to the function (convert) and get the corresponding Fahrenheit value.

Programming Concepts 21

Assignment 3(a):- Produce user documentation for the above completed programming application (Task 02) including the user interface design.

In this application we convert the value of Celsius to Fahrenheit. When user run this program then user has to enter the two values i.e. stating value of Celsius and ending value of Celsius after that the program gives the Fahrenheit value in the difference of 10. So by using this program user can easily convert the Celsius into Fahrenheit.

Design:-

Programming Concepts 22

Assignment 3(b):- Develop documentation for the pre-described program application

The Given program application is very simple. in this user have to enter the values of two array i.e. Array P and Array Q. then program checks that is there any same value of P array in the Q array if yes then program display the message and terminates the program. Suppose you enter 27 in P array as well as in Q array then it will show the message that 27 exists in the P & Q array.

Programming Concepts 23

Assignment 4(a):- Discrimination between semantic and syntax errors.

In the C/C++ there are four types of error that will be effect on your program. They are:-

1.) Syntax Error: - These are those errors which don't match the rules of the programming. For example after writing a statement there must be a semicolon is you don't put the semicolon then it is a syntax error.

2.) Semantic Error:- Semantic error are logical errors means when there is an error in the meaning of the program for example if we make a program to convert the Celsius to Fahrenheit and the output of the program is not correct then there is a logical error in the program that does not diagnose by the compiler.

3.) Runtime Error: - Runtime errors are those errors when there is no sufficient memory for the allocation of the program means when a error is generated due to insufficient of memory then that type of errors are known as runtime errors.

4.) Compile Errors: - These errors are generated at the time of compilation means when we compile the program at that time error is generated due to no matching function, unsatisfied incomplete type, and bad argument cannot allocate an object then that type of error is known as compile time errors.

Programming Concepts 24

Assignment 4(b):-Produce test documentation

Programming Concepts 25

Assignment 4(c):-Successfully construct and use test data and schedules to detect logic errors

Programming Concepts 26

Assignment 4(d):-Use appropriate techniques for detecting errors

Programming Concepts 27

Conclusion and Recommendation:-

By solving this assignment we learned many concepts of C/C++ programming languages like Input/Output Statements, Operators, Control Structure, Arrays, and Functions.

In the first task we learned about the various operators of the C/C++ language and also get the knowledge about the various Input/Output statements and also know that how the values of the arrays are compared. To complete these task we also use the control structure like for loop, if-else statements etc.

In the second task we learned that how to use the functions in the program means how to define the functions and how to call the function at the run/compile time.

In the last task of the assignment we learned about the various errors occurred in the C/C++ language and get the knowledge of techniques for detecting errors.

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.