Computer Programming Lab Manual - 1-9
Computer Programming Lab Manual - 1-9
List of Practicals
Lab 03: Creating Documents with Advance Formatting Operations of Microsoft Word
Lab 04: Creating and Editing Multimedia Presentations with Microsoft PowerPoint
Table of Contents
Lab 01: Installing Windows Operating System and Disk Partitioning.... .1
1.1 Tools................................................................................................................ 1
1.2 Background...................................................................................................... 1
1.2.1 Operating System..................................................................................... 1
1.2.2 Bootable Media......................................................................................... 1
1.2.3 Rufus......................................................................................................... 2
1.3 Procedure........................................................................................................ 2
Creating bootable USB using Rufus.......................................................................2
Installing Windows 10 from bootable USB.............................................................3
EXERCISE............................................................................................................... 8
Lab 02: Creating and Editing Documents with Microsoft Word...............9
2.1 Tools................................................................................................................ 9
2.2 Background...................................................................................................... 9
2.2.2 Microsoft Word 2013 Interface...............................................................9
2.2.2.1 Home Tabs......................................................................................... 11
2.2.2.2 Insert Tabs......................................................................................... 11
2.3 Formatting Text............................................................................................. 11
2.4 Procedure...................................................................................................... 11
2.4.1 Creating a blank document..................................................................11
2.4.2 Changing the font of text.....................................................................12
2.4.3 Changing the font size.........................................................................12
2.4.4 Changing the font color.......................................................................12
2.4.5 Using the Bold, Italic, and Underline commands..................................12
2.4.6 Changing the text case........................................................................13
2.4.7 Changing the text alignment...............................................................13
2.4.8 Changing line spacing..........................................................................13
2.4.9 Changing paragraph spacing...............................................................13
2.4.10 Changing paragraph indent...................................................................13
2.4.11 Creating bulleted list.............................................................................14
2.4.12 Creating numbered list..........................................................................14
2.4.13 Creating multilevel list...........................................................................14
2.4.14 Creating header and footer...................................................................15
2.4.15 Adding page number to a document.....................................................15
2.4.16 Inserting a picture from a file................................................................15
2.4.17 Wrapping text around an image............................................................15
Computer Programming
EXERCISE............................................................................................................. 16
Lab 03: Creating Documents with Advance Formatting Operations of
Microsoft Word.................................................................................19
3.1 Tools.............................................................................................................. 19
3.2 Background.................................................................................................... 19
3.2.1 Tables in MS Word............................................................................... 19
3.2.2 Smart Art............................................................................................. 19
3.2.3 Symbols............................................................................................... 19
3.2.4 Equations............................................................................................. 19
3.3 Procedure..................................................................................................... 20
3.3.1 Creating a blank table.............................................................................20
3.3.2 Modifying tables....................................................................................... 20
3.3.2.1 To add a row or column.....................................................................20
3.3.2.2 To delete a row or column.................................................................20
3.3.2.3 To apply a table style........................................................................20
3.3.2.4 Merge and Split Cells.........................................................................21
3.3.2.5 Splitting a table................................................................................. 21
3.3.3 To insert a SmartArt graphic....................................................................21
3.3.3.1 To add text to a SmartArt graphic.................................................22
3.3.3.2 To change the SmartArt layout......................................................22
3.3.4 To insert a symbol................................................................................ 23
3.3.5 To insert an equation...........................................................................23
EXERCISE............................................................................................................. 24
Lab 04: Creating and Editing Multimedia Presentations with Microsoft
PowerPoint......................................................................................27
4.1 Tools.............................................................................................................. 27
4.2 Background.................................................................................................... 27
4.2.1 MS PowerPoint..................................................................................... 27
4.2.2 The PowerPoint 2013 Interface............................................................27
4.2.3 The Ribbon........................................................................................... 28
4.2.3.1 Home Tab.......................................................................................... 28
4.2.3.2 Insert Tab.......................................................................................... 28
4.2.3.3 Design Tab......................................................................................... 28
4.2.3.4 Transitions Tab.................................................................................. 28
4.2.3.5 Animations Tab.................................................................................. 29
4.2.4 Backstage view........................................................................................ 29
4.2.5. Slide Basics............................................................................................. 30
4.2.6 Themes................................................................................................... 30
Computer Programming
4.2.7 Transitions............................................................................................... 30
4.3 Procedure...................................................................................................... 31
4.3.1 Creating a new presentation................................................................31
4.3.2 Inserting new slide............................................................................... 32
4.3.2.1 Managing slides................................................................................. 32
4.3.2.2 Customizing slides............................................................................. 32
4.3.2.3 Applying Transitions......................................................................32
EXERCISE............................................................................................................. 33
Lab 05: Creating Presentations with Advance Operations of Microsoft
PowerPoint......................................................................................36
5.1 Tools.............................................................................................................. 36
5.2 Background.................................................................................................... 36
5.2.1 Word Art............................................................................................... 36
5.2.2 Chart.................................................................................................... 36
5.2.3 Animating Text and Objects.................................................................36
5.3 Procedure...................................................................................................... 37
5.3.1 Inserting a picture................................................................................ 37
5.3.2 Applying WordArt style to a text..........................................................37
5.3.3 Inserting a shape................................................................................. 38
5.3.4 Inserting an audio................................................................................ 38
5.3.5 Inserting an video................................................................................ 38
5.3.6 Inserting a blank table.........................................................................38
5.3.7 Modifying tables................................................................................... 38
5.3.7.1 To add a row or column.................................................................38
5.3.7.2 To delete a row or column.............................................................39
5.3.8 To insert a chart................................................................................... 39
5.3.8.1 To apply an animation to an object...............................................40
5.3.8.2 To add multiple animations to an object........................................40
5.3.8.3 To open the Animation Pane..........................................................41
5.3.8.4 To change an effect's start option.................................................41
EXERCISE............................................................................................................. 42
Lab 06: Creating and Editing Spreadsheets with Microsoft Excel.........46
6.1 Tools.............................................................................................................. 46
6.2 Background.................................................................................................... 46
6.2.1 MS Excel............................................................................................... 46
6.2.2 The Excel 2013 Interface.....................................................................46
6.2.3 The Ribbon........................................................................................... 47
Computer Programming
Upon successful completion of this lab the students will be able to:
• Create bootable media for Windows installation.
• Install Windows 10 via bootable USB stick.
• Create partitions using windows setup and disk management.
1. TOOLS
1
• Bootable Windows 10 ISO file.
• Removable media (USB 4GB or more).
• Rufus software.
1. BACKGROUND
2
1.2.1 Operating System
Operating system is a system software that enables the computer hardware to
communicate and operate with the computer software. It control’s computer
hardware and interacts with the user and application software. Number of
operating systems are available, few of them are listed below:
1.2.3 Rufus
Rufus is the utility used to format and create bootable USB drives, pen drives,
flash cards etc. Rufus supports both, Master Boot Record (MBR) or GUID Partition
Table (GPT) partition systems.
In other computers you just need to access boot order and select the bootable
USB.
Note: Setup key on different computer vary, some of the possible keys are: Esc,
Del, F2, F10)
Step 09: Select and remove all partitions from the Disk.
10: Select unallocated space and click New, specify the size in MBs for new
partition.
Figure 1.7: Step 09, 10 & 11 – Copying files and installing windows
14: After the installation is completed, the computer will reboot.
21: The setup has successfully installed windows 10 and the desktop
appears.
EXERCISE
1.1: Create a bootable Windows 10 USB. Note: use any tool
other than Rufus.
Upon successful completion of this lab the students will be able to:
• Get familiar with MS Word user interface.
• Create and edit documents in MS Word.
• Understand text formatting commands in MS Word.
2. TOOLS
1
• PC with MS Word (Version: 2016, 2013, 2010 or 2007)
2. BACKGROUND
2
2.2.1 Microsoft Word
When you use a computer program to create, edit, and format text documents,
you are performing a task known as word processing. Part of the Microsoft Office
suite of programs, Microsoft Word, is one of the most sophisticated word-
processing programs available.
By using Word, it is easy to efficiently create a wide range of business and
personal documents, from the simplest letter to the most complex report.
Word interface.
Figure 2.1: MS Word Start Screen
The Home tab gives you access to some of the commonly used commands.
The Insert tab allows you to insert pictures, charts, tables, shapes, cover pages,
and more to your document.
Font size box: When the font size you need is not available in the Font size drop-
down arrow, you can click the Font size box and type the desired font size. Then
press Enter.
Step 02: On the Home tab, click the drop-down arrow next to the Numbering
command. A menu of numbering styles will appear.
Step 03: Move the mouse over the various numbering styles. A live preview of
the numbering style will appear in the document.
Step 04: Select the numbering style you wish to use.
Step 04: To resize an image, click and drag one of the corner sizing handles .
The image will change size while keeping the same proportions. If you want to
stretch it horizontally or vertically, you can use the side sizing handles .
EXERCISE
Exercise 2.1: Create and format the following MS WORD document page:
Exercise 2.2: Create and format the following MS WORD document page:
Exercise 2.3: Create and format the following MS WORD document page:
Exercise 2.4: Create and format the following MS WORD document page:
Classification of Computers
o On the basis of Purpose
o On the basis of Size
o On the basis of Working Mechanism
Classification of Computers (Purpose)
o General Purpose
o Special Purpose
Classification of Computers (Size)
o Super Computers
o Mainframe Computers
o Mini Computers
o Micro Computers
Desktop Computers
Workstations
Notebook Computers
Tablet PCs
Handheld Computers
Smartphones
Classification of Computers (Working Mechanism)
o Analog Computers
o Digital Computers
o Hybrid Computers
1. Software
2. Types of Software
a. System Software
i. System Management
ii. System Support
iii. System Development
b. Application Software
i. General Purpose
ii. Application Specific
Upon successful completion of this lab the students will be able to:
• Insert, format and design the tables in MS Word.
• Insert and format smart art in MS Word.
• Insert symbols and design equations in MS Word.
3. TOOLS
1
• PC with MS Word (Version: 2016, 2013, 2010 or 2007)
3. BACKGROUND
2
3.2.1 Tables in MS Word
A table is a grid of cells arranged in rows and columns. Tables are useful for
various tasks such as presenting text information and numerical data. MS Word
allows you to create and design any type of table. Once created you can merge
multiple cells whether in column or rows to create table with different number of
columns in each row. You can insert a table in word document from Insert tab.
3.2.3 Symbols
Sometimes you may find that you need to add a symbol to your text, such as the
Copyright symbol, ©. Word offers a large collection of symbols for currency,
languages, mathematics, and more.
3.2.4 Equations
MS Equation Editor allows you to design any form of mathematical equation. It
contains many place holders for different operations and bundle of symbols.
3.3 PROCEDURE
3.3.1 Creating a blank table
Step 01: Place your insertion point where you want
the table, then select the Insert tab.
Step 02: Click the Table command.
Step 03: A drop-down menu containing a grid of
squares will appear. Hover the mouse over the grid to
select the number of columns and rows in the table.
Step 04: Click the mouse, and the table will appear in
the document.
Step 05: You can now place the insertion point
anywhere in the table to add text.
Step 01: Place the insertion point in the row or column you want to delete.
Step 02: Right-click the mouse, then select Delete Cells... from the menu that
appears.
Step 03: A dialog box will appear. Select Delete entire row or Delete entire
column, then click OK.
Step 01: Click anywhere on the table, then click the Design tab on the right side
of the Ribbon.
Step 02: Locate the Table Styles group, then click the More drop-down arrow to
see all available table styles.
Step 03: Select the desired style.
Some tables require a layout that doesn't conform to the standard grid. In those
cases, you may need to merge or split cells.
Merging
Step 01: Bring your mouse pointer position inside the first cell that you want to
merge.
Step 02: Now press the Shift key and click the cells around the cell which you
want to merge into the first cell. This will highlight the cells which you click and
they will be ready to be merged.
Step 03: Now click the Layout tab and then click the Merge Cells button which
will merge all the selected cells.
Splitting
Step 01: Bring your mouse pointer position inside the cell that has to be divided
into multiple cells.
Step 02: Now click the Layout tab and then click the Split Cells button; this will
display a dialog box asking for the number of rows and columns to be created
from the selected cell.
Step 03: Select the desired number of rows and columns that have to go into the
resultant cell and finally click the OK button to apply the result.
Step 01: Select the SmartArt graphic. The SmartArt task pane will appear to the
left.
Step 02: Enter text next to each bullet in the task pane. The text will appear in
the graphic and will resize to fit inside the shape.
Step 03: To add a new shape, press Enter. A new bullet will appear in the task
pane, and a new shape will appear in the graphic. You can delete any bullets
you're not using to remove the shapes.
Step 01: Select the SmartArt graphic, then select the Design tab.
Step 02: In the Layouts group, click the More drop-down arrow.
Step 03: Select the desired layout, or click More Layouts... to see even more
SmartArt options.
symbol.
EXERCISE
Exercise 3.1: Create the following table in MS Word:
Shopping Bill
General Purpose
Purpose
Special Purpose
Super
Desktop
Mainframe
Size Workstation
Classification of
Computers Mini
Notebook
Micro
Tablet
Analog
Handheld
Type of
Data/Working Digital
Mechanism
Smart Phone
Hybrid
Upon successful completion of this lab the students will be able to:
• Get familiar with MS PowerPoint user interface.
• Create and edit multimedia presentations in MS PowerPoint.
4. TOOLS
1
• PC with MS PowerPoint (Version: 2016, 2013, 2010 or 2007)
4. BACKGROUND
2
4.2.1 MS PowerPoint
PowerPoint 2013 is a presentation software that allows you to create dynamic
slide presentations. Slideshows can include animation, narration, images, videos,
and much more.
Microsoft Office product that provides users with an interface to design
multimedia slides to be displayed on a projection system or personal computer.
The software incorporates images, sounds, videos, text, and charts to create an
interactive presentation. Microsoft PowerPoint interacts with other Office
products such as Microsoft Word and Excel, and is included with most Microsoft
Office packages.
He Home tab gives you access to the most commonly used commands, including
copy and paste, formatting, and the New Slide command.
The Insert tab allows you to insert pictures, charts, tables, shapes, videos and
more, which can help you communicate information visually and add style to
your presentation.
The Design tab allows you to apply themes. A theme is a predefined combination
of colors, fonts, and effects that can quickly change the look and feel of your
entire slide show.
The Transitions tab allows you to apply slide transitions. Transitions are the
movements you see between slides when presenting your slide show.
Figure4 5: Transition
s Tab
.
4.2.3.5 Animations Tab
The Animations tab allows you to animate text and objects such as clip art,
shapes and pictures. Animation can be used to draw attention to specific content
or make the slide easier to read.
4.2.6 Themes
A theme is a predefined combination of colors, fonts, and effects. Different
themes also use different slide layouts. Elements of theme are:
Theme Colors: There are 10 theme colors, along with darker and lighter
variations, available from every Color menu.
Theme Fonts: There are two theme fonts available at the top of the Font menu
under Theme Fonts.
Theme Effects: These affect the preset shape styles. You can find shape styles on
the Format tab whenever you select a shape or SmartArt graphic.
4.2.7 Transitions
Transitions are the movements you see between slides when presenting your
slide show. A transition can be as simple as fading to the next slide, or it can be
a flashy, eye-catching effect. PowerPoint makes it easy to apply transitions to
some or all your slides, giving your presentation a polished, professional look.
There are three categories of unique transitions to choose from, all of which can
be found on the Transitions tab:
Subtle: These are the most basic types of transitions. They use simple
animations to move between slides.
themselves. When used correctly, dynamic transitions can help to unify your
slides and add a further level of polish to your presentation.
Step 01: To duplicate slides, select the slide you wish to duplicate, right-click the
mouse, and choose Duplicate Slide from the menu that appears.
Step 02: To move a slide just click, hold, and drag the desired slide in the Slide
Navigation pane to the desired position.
Step 03: To delete a slide simply select the slide you wish to delete, then press
the Delete or Backspace key on your keyboard.
Step 01: To change the slide size, select the Design tab, then click the Slide Size
command. Choose the desired slide size from the menu that appears
(Widescreen 16-by-9 or standard 4by-3)
Step 02: To format slide background, select the Design tab, then click the Format
Background command. Finally select the desired fill options
Step 03: To apply a theme, select the Design tab on the Ribbon, then click the
More dropdown arrow to see all the available themes. Select the desired theme.
Step 01: Select the desired slide from the Slide Navigation pane. This is the slide
that will appear after the transition.
Step 02: Click the Transitions tab, then locate the Transition to This Slide group.
By default, None is applied to each slide.
Step 03: Click the More drop-down arrow to display all transitions.
Step 04: Click a transition to apply it to the selected slide. This will automatically
preview the transition.
EXERCISE
Exercise 4.1: Create the following presentation in MS PowerPoint, also apply the
transitions.
Upon successful completion of this lab the students will be able to:
• Insert images, audio, video, WordArt, shapes, tables and charts in
PowerPoint presentation.
• Apply animations to text and objects.
5. TOOLS
1
• PC with MS PowerPoint (Version: 2016, 2013, 2010 or 2007)
5. BACKGROUND
2
5.2.1 Word Art
PowerPoint allows you to add effects to the text inside of a text box, which is
known as WordArt. For the most part, the types of effects you can add are the
same as the ones you can add to shapes and text boxes (shadow, bevel, etc.).
However, with WordArt, you can also Transform the text to give it a wavy,
slanted, or inflated look.
5.2.2 Chart
A chart is a tool you can use to communicate data graphically. Including a chart
in a presentation allows your audience to see the meaning behind the numbers,
which makes it easy to visualize comparisons and trends.
5. PROCEDURE
3
5.3.1 Inserting a picture
Step 01: Select the Insert tab, then click the Pictures command in the Images
group.
Step 02: A dialog box will appear. Locate and select the desired image file, then
click Insert.
Step 03: You can also click the Pictures command in a placeholder to insert
images.
Step 01: Click a cell adjacent to the location where you wish to add a row or
column.
Step 02: Click the Layout tab on the right side of the Ribbon.
Step 03: Locate the Rows & Columns group. If you want to insert a new row,
select either Insert Above or Insert Below. If you want to insert a new column,
select either Insert Left or Insert Right.
Step 01: Select the desired row or column by clicking any cell in that row or
column, then select the Layout tab.
Step 02: In the Rows & Columns group, click the Delete command, then select
Delete Rows or Delete Columns from the menu that appears.
Step 04: A chart and a spreadsheet will appear. The data that appears in the
spreadsheet is placeholder source data you will replace with your own
information. The source data is used to create the chart.
Step 06: When you're done, click the X to close the spreadsheet.
Step 01: From the Animations tab, click the Animation Pane command.
Step 02: The Animation Pane will open on the right side of the window. It will
show all of the effects for the current slide in the order in which they will appear.
Step 03: If you have several animated objects, it may help to rename the objects
before reordering them in the Animation Pane. You can rename them in the
Selection Pane. To open the Selection Pane, click an object, then from the Format
tab click Selection Pane. Double-click the name of an object to rename it.
Step 01: On the Animation Pane, click and drag an effect up or down.
Step 02: The effects will reorder themselves.
EXERCISE
Exercise 5.1: Create the following presentation in PowerPoint, use animations
and transitions as well.
Upon successful completion of this lab the students will be able to:
• Get familiar with MS Excel user interface.
• Create and edit spreadsheets in MS Excel.
6. TOOLS
1
• PC with MS Excel (Version: 2016, 2013, 2010 or 2007)
6. BACKGROUND
2
6.2.1 MS Excel
MS Excel is a spreadsheet program that allows you to store, organize, and
analyze information. While you may think that Excel is only used by certain
people to process complicated data, anyone can learn how to take advantage of
Excel's powerful features. Whether you're keeping a budget, organizing a
training log, or creating an invoice, Excel makes it easy to work with different
kinds of data.
He Home tab gives you access to the most commonly used commands, including
copy and paste, formatting, and number styles.
The Insert tab allows you to insert pictures, charts, tables, sparklines, filers and
more, which can help you visualize and communicate your workbook data
graphically.
The Formulas tab gives you access to the most commonly used functions and
formulas. These commands will help you calculate and analyze numerical data,
like average and percentage..
Figure6 5: FormulaTab
.
6.2.3.4 Data Tab
The Data tab makes it easy to sort and filter information in your workbook, which
can be especially helpful if your project contains large amount of data.
Figure6 6: DataTab
.
6.2.3.5 Worksheet Views
Excel 2013 has a variety of viewing options that change how your workbook is
displayed. You can choose to view any workbook in Normal view, Page Layout
view, or Page Break view. These views can be useful for various tasks, especially
if you're planning to print the spreadsheet.
6.2.5 Cell
Every worksheet is made up of thousands of rectangles, which are called cells. A
cell is the intersection of a row and a column. Columns are identified by letters
(A, B, C), while rows are identified by numbers (1, 2, 3).
Each cell has its own name, or cell address, based on its column and row. In this
example, the selected cell intersects column C and row 5, so the cell address is
C5. The cell address will also appear in the Name box. Note that a cell's column
and row headings are highlighted when the cell is selected.
Step 02: To delete a worksheet, right-click the worksheet you wish to delete,
then select Delete from the worksheet menu.
Step 03: To copy a worksheet, right-click the worksheet you want to copy, then
select Move or Copy from the worksheet menu.
Step 02: A border will appear around the selected cell, and the
column heading and row heading will be highlighted. The cell will remain
selected until you click another cell in the worksheet.
EXERCISE
Exercise 6.1: Create the following account worksheet in MS Excel:
Exercise 6.2: Create the following simple student test results worksheet in MS
Excel:
Upon successful completion of this lab the students will be able to:
• Insert and create simple and complex formulas in MS Excel.
• Create and use functions in MS Excel.
• Sort and filter the data in MS Excel.
• Create and insert charts in MS Excel worksheets.
7. TOOLS
1
• PC with MS Excel (Version: 2016, 2013, 2010 or 2007)
7. BACKGROUND
2
7.2.1 Formatting text and numbers
One of the most powerful tools in Excel is the ability to apply specific formatting
for text and numbers. Instead of displaying all cell content in exactly the same
way, you can use formatting to change the appearance of dates, times,
decimals, percentages (%), currency ($), and much more.
Excel uses standard operators for formulas, such as a plus sign for addition (+), a
minus sign for subtraction (-), an asterisk for multiplication (*), a forward slash
for division (/), and a caret (^) for exponents.
All formulas in Excel must begin with an equals sign (=).
This is because the cell contains, or is equal to, the formula
and the value it calculates.
7.3 FUNCTIONS
A function is a predefined formula that performs calculations using specific
values in a particular order. Excel includes many common functions that can be
useful for quickly finding the sum, average, count, maximum value, and
minimum value for a range of cells. In order to use functions correctly, you'll
• SUM: This function adds all of the values of the cells in the argument.
• AVERAGE: This function determines the average of the values included in
the argument. It calculates the sum of the cells and then divides that
value by the number of cells in the argument.
• COUNT: This function counts the number of cells with numerical data in
the argument.
This function is useful for quickly counting items in a cell range.
• MAX: This function determines the highest cell value included in the
argument.
• MIN: This function determines the lowest cell value included in the
argument.
7.6 CHARTS
It can often be difficult to interpret Excel workbooks that contain a lot of data.
Charts allow you to illustrate your workbook data graphically, which makes it
easy to visualize comparisons and trends.
Excel has several different types of charts, allowing you to choose the one that
best fits your data. In order to use charts effectively, you'll need to understand
how different charts are used.
In addition to chart types, you'll need to understand how to read a chart. Charts
contain several different elements, or parts, that can help you interpret the data.
7. PROCEDURE
7
7.7.1 To apply number formatting
Step 01: Select the cells(s) you wish to modify.
Step 02: Click the drop-down arrow next to the Number Format command on the
Home tab. The Number Formatting drop-down menu will appear.
Step 03: Select the desired formatting option. In our example, we will change the
formatting to Long Date.
Step 04: The selected cells will change to the new formatting style. For some
number formats, you can then use the Increase Decimal and Decrease Decimal
commands (below the Number Format command) to change the number of
decimal places that are displayed.
Step 02: Type the equals sign (=). Notice how it appears in both the cell and the
formula bar.
Step 03: Type the cell address of the cell you wish to reference first in the
formula: cell B1 in our example. A blue border will appear around the referenced
cell.
Step 04: Type the mathematical operator you wish to use. In our example, we'll
type the addition sign (+).
Step 05: Type the cell address of the cell you wish to reference second in the
formula: cell B2 in our example. A red border will appear around the referenced
cell.
Step 06: Press Enter on your keyboard. The formula will be calculated, and the
value will be displayed in the cell.
Step 02: Enter your formula. In our example, we'll type =B2*C2+B3*C3. This
formula will follow the order of operations, first performing the multiplication:
2.29*20 = 45.80 and 3.49*35 = 122.15. Then, it will add those values together
to calculate the total: 45.80+122.15.
Step 03: Double-check your formula for accuracy, then press Enter on your
keyboard. The formula will calculate and display the result. In our example, the
result shows that the total cost for the order is $167.95.
Step 02: Type the equals sign (=) and enter the desired function name. You can
also select the desired function from the list of suggested functions that will
appear below the cell as you type. In our example, we'll type =AVERAGE.
Step 03: Enter the cell range for the argument inside parentheses. In our
example, we'll type (C3:C10). This formula will add the values of cells C3:C10
and then divide that value by the total number of cells in the range to determine
the average.
Step 04: Press Enter on your keyboard. The function will be calculated, and the
result will appear in the cell. In our example, the average price per unit of items
ordered was $15.93.
Step 02: In the Editing group on the Home tab, locate and select the arrow next
to the AutoSum command and then choose the desired function from the drop-
down menu. In our example, we'll select Sum.
Step 03: The selected function will appear in the cell. If logically placed, the
AutoSum command will automatically select a cell range for the argument. In our
example, cells D3:D11 were selected automatically and their values will be
added together to calculate the total cost. You can also manually enter the
desired cell range into the argument.
Step 04: Press Enter on your keyboard. The function will be calculated, and the
result will appear in the cell. In our example, the sum of D3:D11 is $606.05.
Step 02: Click the Formulas tab on the Ribbon to access the Function Library.
Step 03: From the Function Library group, select the desired function category.
In our example, we'll choose Date & Time.
Step 04: Select the desired function from the drop-down menu. In our example,
we'll select the NETWORKDAYS function to count the number of business days
between the ordered date and received date.
Step 05: The Function Arguments dialog box will appear. From here, you'll be
able to enter or select the cells that will make up the arguments in the function.
In our example, we'll enter B3 in the Start_date: field and C3 in the End_date:
field.
Step 06: When you're satisfied with the arguments, click OK.
Step 07: The function will be calculated, and the result will appear in the cell. In
our example, the result shows that it took four business days to receive the
order.
Step 02: Select the Data tab on the Ribbon, then click the Ascending command
sort ascending to Sort A to Z, or the Descending command sort ascending to Sort
Z to A. In our example, we'll click the Ascending command.
Step 03: The worksheet will be sorted by the selected column. In our example,
the worksheet is now sorted by last name.
Step 02: Select the Data tab on the Ribbon, then click the Sort command.
Step 03: The Sort dialog box will appear. Choose the column you wish to sort by.
In our example, we want to sort the data by the number of T-shirt orders, so we'll
select Orders.
Step 04: Decide the sorting order (either ascending or descending). In our
example, we'll use Smallest to Largest.
Step 05: Once you're satisfied with your selection, click OK.
Step 06: The cell range will be sorted by the selected column. In our example,
the Orders column will be sorted from lowest to highest. Notice that the other
content in the worksheet was not affected by the sort.
Step 02: A drop-down arrow will appear in the header cell for each column.
Step 03: Click the drop-down arrow for the column you wish to filter. In our
example, we will filter column B to view only certain types of equipment.
Step 04: The Filter menu will appear.
Step 05: Uncheck the box next to Select All to quickly deselect all data.
Step 06: Check the boxes next to the data you wish to filter, then click OK. In this
example, we will check Laptop and Tablet to view only those types of equipment.
Step 07: The data will be filtered, temporarily hiding any content that doesn't
match the criteria. In our example, only laptops and tablets are visible.
Step 02: From the Insert tab, click the desired Chart command. In our example,
we'll select Column.
Step 03: Choose the desired chart type from the drop-down menu.
Step 04: The selected chart will be inserted in the worksheet.
EXERCISE
Exercise 7.1: Create the following worksheet for marksheet generation:
Exercise 7.4: Create the following worksheet and insert bar charts:
Exercise 7.5: Create the following worksheet and insert pie chart:
Exercise 7.6: Create the following worksheet and insert scattered charts:
Upon successful completion of this lab the students will be able to:
• Get familiar with Disk Operating System (DOS) Command Line Interface.
• Understand the syntax and execute MS DOS commands.
8.1 TOOLS
• PC with MS-DOS or Command Prompt.
8.1 BACKGROUND
8.2.1 MS-DOS
Short for Microsoft Disk Operating System, MS-DOS is a non-graphical command
line operating system created for IBM compatible computers. MS-DOS was first
introduced by Microsoft in August 1981 and was last updated in 1994 with MS-
DOS 6.22.
• Internal Commands
• External Commands
names
ERASE [/P] [/F] [/S] [/Q]
[/A[[:]attributes]] names
DIR
[drive:][path][filename]
[/A[[:]attributes]] [/B]
Displays a list of files and [/C] [/D] [/L] [/N]
7 DIR [/O[[:]sortorder]] [/P]
subdirectories in a directory.
[/Q] [/R] [/S]
[/T[[:]timefield]] [/W]
[/X] [/4]
Quits the CMD.EXE program
8 EXIT (command interpreter) or the EXIT [/B] [exitCode]
current batch script.
Provides help information for
9 HELP HELP [command]
windows commands.
Creates, changes, or deletes the LABEL [drive:][label]
10 LABEL volume label of a disk. LABEL [/MP] [volume]
[label]
11 MD Creates a directory. MKDIR [drive:]path MD
[drive:]path
Moves files and renames files MOVE [/Y | /-Y] [drive:]
12 MOVE and directories. [path]dirname1 dirname2
Listing files in MS-DOS that contain c, mp, and any other character in-between.
For example, comp, camp, c2mp, and c-mp would all be matched.
dir c?mp
In this next example the dir command would only list files that end with .MP3 file
extension. dir *.mp3
List any file that ends with data. For example, appdata, mydata, and 123data
would all be matched. dir *data
List any file that is four characters long, begins with he, and has any extension.
For example, help.txt, help.mp3, and heck.jpg would all be matched.
dir he??.*
Rename all files in the current directory that end with the file extension .txt
to .jpg. For example, the file test.txt would become test.jpg.
rename *.txt *.jpg
Deleting files in MS-DOS that begin with comp and end with a .txt extension.
del comp*.txt
Deleting files in a Linux or Unix variant that contain c, mp, and any character in-
between.
rm c?mp
8. PROCEDURE
3
8.3.1 How to open command prompt
Step 01: Click Start button OR open Run dialog box by pressing StartKey+R on
the keyboard.
Step 02: Type cmd and press enter.
Step 03: Command window will appear.
Note:
Typically command prompt starts you at your user directory. In the example
below, the user is Ali, so our prompt is C:\Users\Ali>.
EXERCISE
Exercise 8.1: Write MS DOS commands for the followings (Use wildcard
Characters).
_____________________________________________________________________________
_______________
b) Create three folders named Folder1, Folder2 and Folder3 in your D:
_____________________________________________________________________________
_______________
n) Copy all text files (whose name begin with a) from C:\Windows\System32 in
to
D:\Dummy
_____________________________________________________________________________
_______________
o) Copy all text files (whose name begin with ab) from C:\Windows\System32 in
to
D:\Dummy
_____________________________________________________________________________
_______________
p) Copy all files (whose name begin with z) from C:\Windows\System32 in to D:\
Dummy
_____________________________________________________________________________
_______________
q) Copy all files (whose name begin with b and end with b) from C:\Windows\
System32 in to D:\Dummy
_____________________________________________________________________________
_______________
r) Delete all files from D:\Dummy whose extension start with a
_____________________________________________________________________________
_______________
s) Delete all files from D:\Dummy whose name start with a extension start with
z
_____________________________________________________________________________
_______________
t) Delete all files from D:\Dummy whose name contain aa in their name
_____________________________________________________________________________
_______________
u) Delete the entire directory D:\Dummy
_____________________________________________________________________________
_______________
v) Quick Format USB drive (Write drive letter according to USB drive letter
assigned in your
PC)
_____________________________________________________________________________
_______________
w) Change the label of D: to MyDrive
_____________________________________________________________________________
_______________
Upon successful completion of this lab the students will be able to:
• Getting familiar with basics of C++ programming language.
• Understanding and be able to write and debug simple program in C++.
• Understanding the concept of variable, data types and operators in C++.
TOOLS
Code::Blocks (Version: 13.12) or Bloodshed Dev C++ (Version: 4, 5 or
higher)
9.1 INTRODUCTION
9.1.1 C++ Programming Language
C++ (pronounced "see plus plus") is a general-purpose Object Oriented
Programming language with high-level and low-level capabilities. It is a statically
typed, free-form, multi-paradigm, usually compiled language supporting
procedural programming, data abstraction, object-oriented programming, and
generic programming. C++ is regarded as a mid-level language. This indicates
that C++ comprises a combination of both high-level and low-level language
features.
Bjarne Stroustrup developed C++ in 1979 at Bell Labs as an enhancement to the
C programming language and named it "C with Classes". In 1983 it was renamed
to C++. Enhancements started with the addition of classes, followed by, among
other features, virtual functions, operator overloading, multiple inheritance,
templates, and exception handling. The C++ programming language standard
was ratified in 1998 as ISO/IEC 14882:1998, the current version of which is the
2003 version, ISO/IEC 14882:2003. A new version of the standard (known
informally as C++0x) is being developed.
9.1.3 Code::Blocks
Code::Blocks is a free, open source cross-platform IDE which supports multiple
compilers including GCC, Clang and Visual C++. It is developed in C++ using
wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and
features are defined by the provided plugins. Currently, Code::Blocks is oriented
towards C, C++, and Fortran. It has a custom build system and optional Make
support.
Code::Blocks is being developed for Windows, Linux, and Mac OS X and has been
ported to FreeBSD, OpenBSD and Solaris. Statements are executed on the basis
of conditions.
The program starts with the two lines containing a pound sign (#) and the
keyword include. These are known as preprocessor directives. The preprocessor
directives are the instructions to the part of the compiler known as preprocessor
which includes some extra files (codes) to the basic source program. The files
iostream and conio.h are known as the header files which contain the definitions
of some functions. The iostream header file contains the definition of standard
input/output streams like, cout and cin where as conio.h header file includes the
definitions of function getch(), getche() and others. Simply speaking the
preprocessor directive #include is responsible for including the contents of the
header files into the source file.
using namespace std enables a program to use all the names in any standard C++
header (such as <iostream>) that a program might include.
The main() is the function as the function is always along with the parentheses.
The main() function is the first executable function in any C++ program. No
matter where the main() function is located always the first precedence goes to
the main() function and its contents. The contents of main function are enclosed
in curly braces. The void before the main function says that the function main
has no return type value and at the end of the function main() will not return any
value.
The braces “{ “and “}” also known as curly braces, enclose the block of code
present in any function. “{“ is known as the opening brace and ”}” is known as
closing brace. Opening brace shows the starting of the main or any function and
closing brace shows the ending of the main or any function. The code of each
and every function is always enclosed in the curly braces.
The cout<<”My name is Ali Asghar” tells the computer to print the string constant
“My name is Ali Asghar” on the console screen. The cout is the standard output
stream which directs the flow of data to the console screen. What ever written in
the double quotations in cout statement is printed as it is on the console screen.
Every C++ statement must end with a semicolon (also known as the statement
terminator). Preprocessor directives (like #include) do not end with a semicolon.
The getch() (get character) function waits to get the character from keyboard. If
you run your program without using getch() your program will show the result in
just one blink and will vanish out quickly. So to make the output console screen
stop in order to examine the results clearly we use getch() function. The
definition of the function getch() is present in the header file “conio.h”.
When the return statement is used at the end of main, the value 0 indicates that
the program has terminated successfully. According to the C++ standard, if
program execution reaches the end of main without encountering a return
statement, it’s assumed that the program terminated successfully— exactly as
when the last statement in main is a return statement with the value 0. For that
reason, we omit the return statement at the end of main in subsequent
programs.
The output of basic.cpp on the console screen may look like as shown in below
figure:
9.1.5 Functions
Functions are the one of the fundamental building blocks of C++ language. The
functions are the sub programs which contain some block of code inside the
curly braces. The code enclosed inside the curly braces is known as the body of
the function. The functions always start with the return type and the function
name followed by the parenthesis. The parentheses tell the compiler that it is a
function not a variable or any other thing. Sometimes the parentheses also
contain arguments, which are the values that the function passes through its
body. As the statements are the instructions to the compiler and they are just
executed from the place where they are placed but if we want to execute the
same block of statements at different places according to the situations of the
program then the function is way which provides us the facility to execute that
same block of statements (codes) at different places. The block of code present
in any function can be executed at any place by calling that function at that
point in the program. Any C++ program can contain number of functions or at
least one i.e. main(). All the C++ programs always contain the main() function,
because it is the gateway to enter in C++ and no program can run with out
main() function.
In basic.cpp, the main() is only the function present. It contains the block of
three line code. This three line code present in main() is always executed first in
this program, because the contents of the main() functions have the highest
precedence as compared to the contents of other functions.
9.1.6 Statements
Statements are the instructions to the computer to work accordingly. All the
statements are always terminated with the terminator “;”. This semicolon is
known as terminator because it terminates the statement and tells the compiler
that the statement has ended. If we don’t give the terminator at the end of any
statement, the compiler will think that the statement is still going on and will
mix another statement or code with it hence giving an error. In basic.cpp, there
is only one statement cout<<”My name is Ali Asghar”; it just tells the computer
to print the string constant present in quotation marks on the console screen. So
every statement is the instruction to the computer and do remember to place
the terminator at the end of each and every statement.
The preprocessor directives are always started with the “#” (hash/pound) sign
which tells the compiler that the thing that you are compiling is a preprocessor
directive which is different from other. And the header files are always enclosed
in “< >” angle brackets following the keyword include but in some cases it is
enclosed in double quotation marks. If you enclose the header file in the angle
brackets it will start the search for the header file in the standard INCLUDE
directory.
#include <iostream>
But when you want to include the user defined header file the header file is
enclosed in quotation marks.
#include “ali.h”
The quotation marks tells the compiler to start the search for the header file in
the current directory—the directory usually containing the source files.
In basic.cpp, there are two header files included in the source program. One is
iostream which contains the definitions of standard input and output streams
like, cout and cin. The other header file is conio.h which contains the basic
definition of the functions like, getch(), getche(), etc.
In above syntax the keyword cout tells the compiler that it is a standard output
stream and treat it as accordingly. The text in the double quotation marks ”My
name is Ali Asghar” is the string constant and is printed on the console screen as
it is. The operator << is known as insertion or put to operator. It directs the
contents of the variable on its right to the object on its left. The insertion
operator can be used multiple times in single cout statement and it is perfectly
legal as in below statement:
cout<<”My name is “<<”Ali Asghar”;
Except printing the string constants, the situation also come in which we have to
print out the values of certain variables on the console screen then we can use
the variable name in cout statement to print its value on the console screen as
in below statement:
cout<<”The addition of two numbers is: “<<Add;
To make the variable Add effective in cout statement it should be declared and
defined properly in the program. You can also print the values of several
variables in using cout statement as in below statement, which prints the
number of apples and oranges in the box.
As the cout is a statement therefore each and every cout statement should be
terminated with the terminator “;”. Let’s examine the following program:
The above program’s code contain three cout statements. The first cout
statement prints the string constant “My name is Ali Asghar.” on the screen as it
is where as “\n” is the escape sequence which moves the cursor to the new line
so that the coming line will be printed on the fresh line. Then the next cout
statement flows the string constant ”I teach at CSE department.”; to the console
screen on the new line. In the last cout statement we face a new unfamiliar word
endl, it is known as the manipulator. The manipulators are the instructions to the
output stream which modify or manipulate the way the data is displayed in the
console screen. The manipulator endl has the same effect of causing a linefeed
as the \n has but it is somewhat clearer. The endl manipulator also causes the
buffer to be flushed. So, on conclusion the third cout statement in SOS.cpp, flows
the string constant ”I live in Jamshoro.” to the console screen on new line.
In above syntax the keyword cin tells the compiler that it is a standard input
stream and treat it as accordingly. The operator >> is known as extraction or
get from operator. It takes the value from stream object on its left and places it
in the variable on its right. Let’s examine the following program
The above program first initializes that the variables a, b and Ans contain the
integer data type values. The first cout statement sends the message to enter
first number from your keyboard and when you enter any number, the cin
statement places that number in the variable a. Then the program gives another
message to enter second number and when you enter any number that will be
placed in the variable b. The statement Ans=a+b then adds the two numbers
and places the result in the variable Ans. Finally the last cout statement shows
the addition of both numbers.
9.1.11 Comments
Commenting is very effective feature in any programming language as it makes
the source program user friendly up to some extent. Comments are un-
executable lines in any source program. Comments make the program more
readable and understandable to the user or even an unknown reader. They help
the programmer to make him remember that for this purpose you have written
this portion of code. And also if a person is unfamiliar with the program, the
comments will help him by telling him what is happening in a certain line or
portion of the program. When you write a program and suppose you are not in
touch with it for a two or three months so when you come back to your program
after such a long period you will forget that for what I had written it and what it
tell? So if you had given the comments in your program you would not be in such
a great trouble.
In small programs it is not a huge problem to forget some code lines but in case
of working on some programs having hundreds or thousands of code line or
working on a project you have to deal with several different blocks of codes so,
in these situations there are a lot of chances to forget the construction of your
own program. So here the comments play their key role.
There are two ways to comment in C++ source file. The first way it to start
comment with the two back slashes “//” , this causes the compiler to consider
the whole line as a comment. The other way is to start the comment with a back
slash and an asterisk “/*” and terminate the comment with an asterisk and back
slash “*/”, which cause the certain block of line as a comment.
The first way only make a single line as a comment but if we want to make the
100 lines as the comment then we can not use the double backslashes “//”
hundred of times. But at this situation the second way suites very well in which
we will place “/*” the starting of the comment and “*/” at the ending of the
comment.
Examine the following program:
9.1.12 Variables
The basic definition of the variable says that the variables are those memory
locations whose value can be varied/altered according to the particular situation.
Like in other programming languages variables are one of the major building
blocks of C++ programming language. The variables set the location into the
memory and give it certain name so you can store certain value and access the
particular location of memory. The name given to the variable is known as
identifier. It is so called because it identifies/indicates certain memory location.
In C++ programming language there are certain rules for identifiers so, being in
the boundary of those you can declare an identifier.
1) The identifier can contain letters form a-z, numbers form 0-9 and an
underscore sign.
2) The identifier can be in upper or lower case but the variable in upper case will
differ from the variable in lower i.e. ANS is not same as ans or Ans.
3) The first character of the identifier must be letter or an underscore sign.
4) The identifier should not contain any space (white space) within it.
5) You can also give underscore sign in the middle of the identifier as an space
for your ease for example, square_inch.
6) The identifier must not be same as the keywords—the words predefined in
C++ which have their own specific meaning and function. Like, main, void,
return, cout, cin etc. are keywords so the identifier should not be like them.
7) The identifier can be as long as you like, but only the first 247 characters (in
Visual C++) or 250 characters (in C++ Builder) will be recognized.
8) The identifier must be unique through out the program i.e. if you have
declared the identifier Var1 so, to access or call it you must give its same
name Var1.
Some valid identifiers are: Var, var, VAR, Var1, VAR1, Var_one, _Var1,
_Var_one_of_one etc.
Some of invalid identifiers are: 1Var, 1_var, void, cout, etc.
Hint: The standard and easy way to declare the identifier is to declare all
characters of its in lower case like, var1, var2 etc.
9.1.12.1 Declaring and Defining a Variable
You might think that the two words declaring and defining are equivalent but in
fact there is a lot of difference between both of them. The declaring is the
process of giving a name to the variable and its data type. The data type means
that which type of value will be stored in that variable whereas the name of the
variable must follow the identifier rules of C++.
int var1;
In above line the variable var1 is initialized with the integer value 50.
In defining a variable we set/initialize some values to the variable before the
compiling.
The above program starts with two preprocessor directives which include two
header files which contain definitions of some functions and keywords as, cout
and getch(). Then in main function one variable mixture is declared and three
variables ethane, methane and propane are defined. The first variable mixture is
only declared as it is only given the name and its data type and no value is set in
the memory location of the variable. Where as in the second variable
initialization statement the memory location is set for the three variables and a
certain value is initialized to the memory location of the variables. The last four
cout statements prints the values of the variable stored in to them on the
console screen with some strings.
Type int occupies 4 bytes (32 bits) of memory. In type int you can store the
integers with in the rage of -2,147,483,648 to 2,147,483,647. To define or
declare a type int variable use the keyword int before the variable name like,
int var1= 1000000000;
Type short occupies 2 bytes (16 bits) of memory. In type short you can store the
integers within the range of -32,768 to 32,767. To define or declare a type short
variable use the keyword short before the variable name like,
short var1=10;
Type long occupies 4 bytes (32 bits) of memory. In type long you can store the
integers with in the rage of -2,147,483,648 to 2,147,483,647. To define or
declare a type long variable use the keyword long before the variable name and
place the letter L after the integer constant like,
long var1=1000000000L;
The numeric data having fractional/decimal part is known as floating point data.
The floating point data can store and represent floating point data. The floating
point data type is of three types i.e. type float, type double and type long
double.
Type float occupies 4 bytes (32 bits) of memory. In type float you can store the
floating point values within the range of 3.8 x 10-38 to 3.8 x 1038 with the
precision of seven (7) digits. To define or declare a type float variable use the
keyword float before the variable name and place the letter F after the floating
point constant like,
float PI=3.1415F; but placing F is optional.
The other two floating point data types are same as type float but they offer
wider range of values and precisions.
Type double occupies 8 bytes (64 bits) of memory. In type double you can store
the floating point values within the range of 1.7 x 10-308 to 1.7 x 10308 with the
precision of fifteen (15) digits. To define or declare a type double variable use
the keyword double before the variable name like,
double PI=3.141592654;
Type long double occupies 10 bytes (80 bits) of memory. In type long double you
can store the floating point values within the range of 1.2 x 10-4932 to 1.2 x
104932 with the precision of nineteen (19) digits. To define or declare a type
long double variable use the keyword long double before the variable name and
place the letter L after the floating point constant like,
long double PI=3.141592654546845348645454L; but placing L is optional.
In floating point data types you can write the floating point constants using
exponential notation, which is the way to write very large or very small numbers
in the power of ten. Like instead of writing 2,000,000,0 you can write 1.0E7 in
exponential notation. Similarly for 52349.2 you can write 5.2E4 and for
0.0000006024 you can write 6.02E-7. double atoms=6.02E-7;
If you want to define a floating point variable then in type float place a letter F in
the end of the constant number, in type double you don’t have to identify the
complier that it is a constant value it considers it as default but in type long
double you have to place the letter L after the constant number. But placing F
and L is optional.
float PI=3.1415F; double PI=3.141592654;
long double
PI=3.141592654546845348645454L;
You can also make the value of the floating point variable constant through out
the function by using the constant qualifier i.e. const. To define a constant
floating point variable place the keyword const before the data type of the
variable as in:
const float PI=3.1415F; const double
PI=3.141592654546845348645454L;
This program defines the constant value of the variable PI and declares the
integer variable radius and a type float variable area. The program gets the
value of radius during the run-time in integer type and then puts it in the
expression area=PI*(radius*radius) and calculates the value of area and finally
shows the value of area.
The above declaration indicates that the variable ch is a character type data
variable and in the program it will only store the characters. And to define a
variable you can either give the character in single quotation marks or you can
give the ASCII equivalent to that character. For example if we want to store the
character A (capital A letter) in the variable ch then we can write as in,
char ch=’A’;
char ch=65;
In first line the character A is enclosed in single quotation marks so the character
A will be store in the variable ch where as in second line the number 65 is the
ASCII equivalent to the character A so the computer will translate it in to
character A and will store it in the variable ch. No matter which method you
perform the aim of both the methods is same.
Examine the following program:
The data types int, short, long and char have their range with in which they can
store certain values and these ranges start from some negative number to
positive number. So by eliminating negative numbers we can extend the size of
the data types. Doing this will make the data types to store large values as twice
as the signed data types do.
The unsigned data types are used when we are dealing with only positive
numbers. To convert a signed data type into an unsigned data type place the
keyword unsigned before the data type as in,
unsigned int var1=12000;
Type unsigned char occupies 1 byte (8 bits) of memory. In type unsigned char
you can store the characters within the range of integers 0 to 255, whereas the
integers 0 to 255 represent the ASCII equivalents to the characters. To declare
an unsigned data type variable use keywords unsigned char before the variable
name as in,
unsigned char ch=250;
Type unsigned short occupies 2 bytes (16 bits) of memory. In type unsigned
short you can store the integers within the range of 0 to 65,535. To declare an
unsigned short data type variable use the keywords unsigned short before the
variable name as in,
unsigned short var1=50;
Type unsigned int and type unsigned long occupy 4 bytes (32 bits) of memory. In
both the data types you can store the integers within the range of 0 to
4,294,967,295. To declare an unsigned int and unsigned long data type use the
keywords unsigned int and unsigned long respectively before the variable names
as in,
unsigned int var1=10000;
It specifies that the variable PI stores the floating point number 3.1415 and this
value will not be altered and will remain constant.
Examine the following program:
are the assignments statements which assign the values to the variable var1.
The assignment statements assign the value from the right of the = sign to the
variable on the left. To assign a variable it must be noted that the variable must
be declared before it is assigned.
In the first cout statement the variables a and b are added, in second the
variables are subtracted, in third the variables are multiplied, in fourth the
variables are divided and in fifth the variable are remaindered. The output of this
program is:
10;
var1=var1*5
0;
var1=var1/va
r2;
electrons=electrons%1;
Operator Description
> Greater than
== Equal to
!= Not equal to
OR || operator combines the Boolean values and makes the condition satisfied
when atleast one comparison becomes true as,
(a>b || a>c || a>d)
Not ! operator combines the Boolean values and makes the condition satisfied
only when all the comparisons become false as,
Operator Description
&& Logical AND
|| Logical OR
! Logical NOT
In first two line codes the value of the variable “ans” is incremented first and
then it is printed on the console screen but in the second two line codes the
value of the variable “ans” is first printed on the console screen and then it is
incremented the one. Operators used as prefix and as postfix behave differently.
In C++,
Word=Word+1 is same as Word += 1 is same as ++Word Word=Word-1
9.2 PROCEDURE
9.2.1 Problem example
Consider the following problem example. We are going to write C++ source code
in Code::Blocks IDE.
Problem statement: Write a program in C++ that accepts the width and the
height of a rectangle from the user and prints the area of the rectangle.
Step 06: Press button and create a new file with .cpp extension by choosing
the destination location of the file.
Step 10: Debug any error in the code and recompile it.
EXERCISE
1. Write a single C++ statement to accomplish each of the following
(assume that using directives have not been used):
a. cout << x;
b. cout << x + x;
5. Write a program that asks the user to enter two numbers, obtains
the two numbers from the user and prints the sum, product,
difference, and quotient of the two numbers.
Create a BMI calculator application in C++ that reads the user’s weight in
pounds and height in inches (or, if you prefer, the user’s weight in kilograms
and height in meters), then calculates and displays the user’s body mass
index.