Docsity

Lab Report and Assignment Guidelines for C++ Programming, Exercises of Computer Programming

Partial preview of the text

Download Lab Report and Assignment Guidelines for C++ Programming and more Exercises Computer Programming in PDF only on Docsity!

Lab Reports

๎€Š

Lab Reports have to be submitted of each lab it

should contain

๎€Š

Your Code (with proper comments)

๎€Š

Flow chart of your code

๎€Š

Screen shots of your results

Assignment Tests

๎€Š

Assignment test will be conducted in every

second lab

๎€Š

It will be of 20 mins duration

๎€Š

Results will be shown within a week

What constitutes PLAGIARISM??

Plagiarism is when you

Copy code (from a fellow or the internet)

Share code (working together)

Borrow code (even just for an idea)

Take or give help in coding (from your fellows, the

internet or anyone else)

Consequences

Your assignment will be cancelled. Both parties

will get ZERO marks.

Further disciplinary action might be taken if need

be.

Programming Languages

โ—

Machine Language

โ—

Assembly Language

โ—

High Level Languages

C++ Language

๎€Š

A very Strong Language

๎€Š

Can do anything

๎€Š

C++ is used to make from very simple

programs to any type of complex programs

including Games and even operating systems

A Simple Program

๎€Š

Writing a Comment

๎€Š

Comments can be written by using //

๎€Š

The compiler ignores everything written after // and

no machine language object code is generated

๎€Š

Commenting is a very good habbit it enables you to

understand your program later

๎€Š

Preprocessor Directive

๎€Š

Lines that begin with # are processed by the

preprocessor before the program is compiled

๎€Š

input/output stream must be included in

any program to output data on screen or to take

input from keyboard

A Simple Program

๎€Š

Main Function

๎€Š

Every Program will start from main even if the

program has alot of functions

๎€Š

The keyword on the left of โ€mainโ€ (e.g int, void)

shows what your main function will return we shall

discuss this in detail when we'll get to functions

๎€Š

How to take output on screen

๎€Š

Cout

๎€Š Standart Output stream

A Simple Program

๎€Š

Escape Characters

๎€Š

The backslash () is called an escape character. It

indicates a special character is to be output

Escape Characters

Character Escape Sequence

New line \n Horizontal Tab \t Vertical Tab \v Return \r Back slash \ Single Quote \โ€™ Double Quote \โ€ Null Character \

// Printing a line with multiple statements. #include // function main begins program execution void main() { std::cout << "Welcome "; std::cout << "to C++!\n"; } // end function main

// Printing multiple lines with a single statement #include // function main begins program execution void main() { std::cout << "Welcome\n to\n \n C++! \n"; } // end function main

Program to add numbers

๎€Š

Variables

๎€Š

Common variable types are

๎€Š int โ€“ integer numbers

๎€Š

char โ€“ characters

๎€Š float โ€“ used for decimal numbers

๎€Š double โ€“ used fordecimal numbers

๎€Š

Int,double and char are often called as fundamental,

primitive or builtin variable types

๎€Š

Must declare before their use

๎€Š

Variable names are case sensitive can contain all

characters, digits and underscores but cannot begin

with a digit

Program to add numbers

๎€Š

Variables

๎€Š

ALWAYS give meaningful names to your variables

๎€Š

Int x,y,z; (not a good practice)

๎€Š Int account_number; (correct)

๎€Š

Always comment your variables for what you are

using them