L P Chro
L P Chro
CSL-110
LAB JOURNAL
1
Obtained
Exp. No Experiment Name Date Sign
Marks
9
Introduction to C/C++ Constructs ,Variable types and
memory
2
EXPERIMENT 01
Objectives
1) To become familiar with the Windows OS environment
2) To become familiar with the hardware of your computer
Background
What is a Computer?
• A computer is a machine that can be instructed to carry out sequences of arithmetic or
logical operations automatically via computer programming. Modern computers have the
ability to follow generalized sets of operations, called programs. These programs enable
computers to perform an extremely wide range of tasks.
• [The American Heritage Dictionary] A device that computes, especially a programmable
electronic machine that performs high-speed mathematical or logical operations or that
assembles, stores, correlates, or otherwise processes information.
It is necessary that you are aware of the hardware in your computer. While the operating system
usually takes care of the complexity of managing the hardware of your computer system,
knowing the hardware helps when you must:
3
3) Diagnose and repair problems in your computer system
TASKS
1) Familiarize yourself with the following basic tasks specific to Windows operating systems
[ask your instructor if you have problems]:
a) Copy and paste a file [select a file, right click > copy; go to the directory to paste into, right
click > paste]
Solution:
4
b) Creating a new file [hint: right click > new > file type]
Solution:
5
Create a new folder [hint: right click > new > folder
Solution:
6
c) Delete a file [hint: select a file, right click > delete]
Solution:
7
2) To check the hardware present in your computer, Right click on My Computer and then click
on Properties note down the specifications of the PC you are working on the default tab.
8
a. What Operating System (OS) is being used in your computer?
Solution:
Windows 10
Solution:
Intel(R) Core (TM) i7-10700 CPU
Solution:
2.9 GHZ
Solution:
16 Gigabytes
9
3) Click on the Remote settings then Computer Name tab.
Solution:
Not Available
Solution:
EE-LAB-31
10
c. What is the name of computer’s workgroup?
Solution:
Bahria University
4) Click on the Hardware tab and then on Device Manager, note all information about hardware
devices here and answer the following questions?
(Hint: you can right-click on any device and see further properties)
11
a) What is the name of the audio inputs and
outputs?
Solution:
S22e-20 (Intel (R) Display Audio
Solution:
NOT AVAILABLE
12
c) Does your computer have a keyboard?
Solution:
YES
d) What is the name of the monitor? Is the proper driver of the monitor installed? Double-click
on the monitor’s name to check the status of the device.
Solution:
Monitor Name: (S22e-20)
Driver: Proper Driver is Installed
Status: This device is working properly
F1: Help
Windows Logo+F1: Help
13
ALT+TAB: Switch between open programs
ALT+F4: Quit a program
SHIFT+DELETE: Delete an item permanently
CTRL+SHIFT+ESC: Opens Windows Task Manager
SHIFT+DELETE: Deletes an item immediately without placing it in the Recycle Bin
TAB: Move to the next control in the dialog box
F6: Move the cursor to address bar in internet explorer
6) What are the key board shortcuts for the following actions?
Solution:
Window + R
Solution:
Window+E
Solution:
ALT+F4
14
d) Minimize all windows
Solution:
Window+D
Solution:
F6
Solution:
Window+TAB
Solution:
CTRL+SHIFT+ESC
Solution:
Window+L
Solution:
SHIFT+DELETE
15
Conclusion:
16
EXPERIMENT 02
Objectives
To become familiar with word processing and enable students to use the various tools in MS
Word effectively to perform common word processing tasks quickly.
Background
Explore Window
Following is the basic window which you get when you start word application. Let us understand
various important parts of this window.
17
Figure: 2.1 Overview MS WORD
18
Backstage View
The Backstage view has been introduced in Word 2010 and acts as the central place for
managing your documents. The backstage view helps in creating new documents, saving and
opening documents, printing and sharing documents, and so on.
Review Tab
The easiest way to correct spelling mistakes is to right click any word that has a red wavy
underline
19
To check more than one word at a time, you can bring up the Spelling and Grammar dialogue
box. To see it, click on the Review tab at the top of Word. On the Review tab, locate the
Proofing section. Then click Spelling & Grammar:
Word count provides the statistics that how many pages, lines and paragraphs etc. are in our
document
Another way To know the current word count of a document, open the document and right
click on the status bar at the bottom of the Word window. The context menu which comes up
will have an entry named “Word Count” which will tell you the current word count.
20
Figure: 2.6 Alternate for Word Count
To insert a comment first select the text then go to “New Comment” on “Comments” group in
“Review” tab. Click on “New Comment” and a new comment will be inserted. You can also
move to next or previous comments and can also delete the comments using this “comments”
group.
To insert a comment in a document, highlight the area of text where you want to comment on.
Click the Review tab on the Ribbon then click New Comment
21
Tracking Group:
With this feature of tracking, you can track and view all changes that are made to the document.
1. While in the document, On the Review tab, under the Tracking group, click Track
Changes.
1. On the Review tab, in the Changes section, click the Next button to move to the next change.
2. Click the Accept or Reject button to accept the change or reject the change and move to the
next change.
3. Keep going until you’ve responded to all the changes.
In “Compare” group there is an option to compare two different documents. This option is
usually used to find out the similarity between two different documents
22
After browsing the paths for original and revised documents click” ok”. A new document will be
opened that will highlight the changes present in the both documents.
View Tab
View tab is used to change the document views. Go through each view and observe the changes
that each view brings.
With MS Word 2010 there is also Quick Access Toolbar which has a save, undo Repeat Typing
button and Customize Quick Access drop down list. Within the list there are New, Open, Save,
E-mail, Quick Print, Print Preview and Print, Spelling & Grammar, Undo, and Redo, Draw
Table, Open Recent File icons. You can also choose to show the Quick Access Toolbar below
the Ribbon by choosing Show below the Ribbon selection and you can also customize further
with the More Commands button and make Microsoft Word 2010 suitable to your preferences
and needs. In such a manner Quick Access Toolbar of MS Word lets you performance routine
tasks much faster. The Microsoft Word 2010 Quick Access toolbar and its functionality are
shown below
Reference Tab
This tab provides the quick way to create table of contents, update it, enter citations or
references, choose any writing styles and footnotes etc. For generating the table of contents first
selects the text from the document to appear in it. After selecting the text, make it a heading from
“Styles” group in home tab. After making different headings, go to “Table of Contents” option in
“Table of Contents” group of “Reference” tab and select any one format.
23
Figure: 2.11 Table of Contents
In “Footnotes” group there is an option to add footnotes and endnotes. Footnotes and endnotes
are an easy way to add or provide the reader with supplementary information and that
information will appear at the end of the page.
To insert a footnote or endnote, navigate to Footnotes section. To insert a footnote, click the
menu option with text as AB1Insert (Placeholder1) Footnote
24
The keyboard shortcuts for inserting a Footnote are Alt + Ctrl + F for inserting an Endnote is
Alt + Ctrl + D
Similarly, citations and bibliography can be inserted from “Citations and Bibliography” group.
The writing styles can also be changes from here as citations depend upon it. In technical writing
we have many different styles of writing that can be select from this group of “Reference” tab.
In “Captions” group, one can give captions to the figures and hence can create the table of
figures in the same manner as table of content were created.
25
Mailing Tab
We can create, and print envelops and labels using this tab. “Start mail merge” are used to create
a form letter which one uses for printing and sending purpose. We can select the recipient also.
Insert Tab
Click the Insert tab and click Table button. This will display a simple grid shown below. When
you move your mouse over the grid cells, it makes a table in the table which appears in the
document. You can make your table having desired number of rows and columns
Click the square representing the lower-right corner of your table, which will create actual table
in your document and word goes in table design mode giving lots of options to work with table
as shown below.
26
Following are the simple steps to “delete” an existing table from a word document.
27
Following are the simple steps to “add an existing picture” in your word document. It is
assumed that you already have a picture available on your PC before you add this picture in your
word document.
Step (1): Click in your document where you want to add a picture.
Step (2): Click the Insert tab and then click Picture option available in illustrations group,
which will display Insert Picture dialog box.
Similarly, you can insert Clip Art, Shapes, and Charts etc.
NAME: ENROLLMENT:
INTRODUCTION TO COMPUTING LAB
Lab Number
Lab Title
Date
Semester & Section
28
Tasks:
a. Type the formatting text in word file with entire document as 12-point Calibri (Body)
in your document.
b. Change the typeface of the entire document to 11-point Verdana.
c. Change all the word occurrences of the to a.
d. Change the spacing of the entire document from single spacing to 1.5.
e. Change the alignment of the entire document to Justify.
f. Set the phrases technology and science in Italic.
g. Change the color of the text.
Formatting Text
Today we are at the dawn of an age of unprecedented technological change. Sometimes referred to
as the Fourth Industrial Revolution, this historic moment has inspired a growing consensus that recent
developments in science and technology are of a unique nature, and likely to impact almost every
facet of our daily lives.
In areas from robotics and artificial intelligence (AI) to the material and life sciences, the coming
decades promise innovations that can help us promote peace, protect our planet, and address the root
causes of suffering in our world. Our enhanced ability to interact through cyberspace is sustaining
and reinforcing these broad technological strides, multiplying the opportunities we must share
information and build knowledge across our increasingly networked planet.
Solution
29
2. Do the following editing on given text
a. Change the text in form of bullets.
b. Change text Case
c. Insert borders and Shades
d. Insert Text Box
e. Insert Page Number
f. Insert a comment (not more than three lines).
Formatting Text
Today we are at the dawn of an age of unprecedented technological change. Sometimes referred to
as the Fourth Industrial Revolution, this historic moment has inspired a growing consensus that recent
developments in science and technology are of a unique nature, and likely to impact almost every
facet of our daily lives.
In areas from robotics and artificial intelligence (AI) to the material and life sciences, the coming
decades promise innovations that can help us promote peace, protect our planet, and address the root
causes of suffering in our world. Our enhanced ability to interact through cyberspace is sustaining
and reinforcing these broad technological strides, multiplying the opportunities we must share
information and build knowledge across our increasingly networked planet
Solution
30
3. Do the following task for the given data
31
a. Insert table and this data in it.
b. Write your name and registration number and insert footnote that shows your academic
qualification.
c. Using the data given to use mailing tab to mail the training date to the given people.
32
d. Insert table of contents that provides the reference to different tasks.
33
e. Show “X Y Scatter plot”
a. Exponential
34
Solution
b. Matrix
Solution
c. Binomial formula
Solution
d. Quadratic formula
Solution
35
e. Integral
Solution
Conclusion:
36
EXPERIMENT 03
Objectives
Background
Microsoft Power Point
Home Tab
To begin Microsoft PowerPoint, go to Start Menu > All Programs > Microsoft Office >
Microsoft PowerPoint 2010. Select PowerPoint Presentation from the Project Gallery if a blank
document does not open.
The Design Ribbon toolbar contains several categories for formatting the design and elements of
your presentation. These include: Home, Insert, Design, Transitions, Animations, Slide Show,
Review and View. The brief introduction of these tabs is;
The Home bar: This has features that allow you to edit Slides, Fonts, Paragraph, Drawing
and Editing.
The Insert bar: This has features that allow you to add Tables, Images, Illustrations,
Links, WordArt, and Media Clips.
The Design bar: This allows you to edit how your presentation will look. It includes
features such as Page Setup, Themes, and Background Styles.
The Transitions bar: This allows you to edit Slide Transitions, Effects, and Transition
Timing. The Animations bar: This allows you to add custom animations to your
presentation. You can select from Preview, Animations, Advance Animation, and
Animation timing.
The Slide Show bar: This has features that allow you to select how your presentation will
be displayed. From here, you can start your Slide Show, Set Up your Slide Show, and
37
Adjust Monitor Settings.
The Review bar: This allows you to Proofread, Translate Languages, Comment Slides,
and Compare your Presentation.
38
The View bar: This has features that allow you to set the View of your Presentation,
Create Master Views, Show/Hide Features, Zoom, Switch from Color to Grayscale,
Adjust Windows, and Add Macros.
1. To create a new slide where you can add content, click the Home tab and select New Slide.
2. Clicking the bottom half of New Slide will give you different new slide options.
These layouts of slides will define the appearance of the slide and the way one can put data into
the slides. The layout of the slides can also be change after they are inserted. In Slides group,
there is a drop-down menu named as “Layout”. By clicking on layout tab and selecting a layout
style, the style of current slide can be changed.
39
Figure: 3.2 Layout
In this tab there is option to cut copy and paste the text. These options are available in
“clipboard” group of Home Tab. Shortcut keys for copy, cut and paste commands are Ctrl+c,
Ctrl+x and Ctrl+v respectively.
Font group allows you to change the font of the text, size, and case etc. of the text. Select the text
first then perform any operation.
In order to change the case of text, select the text you want to change then go to Font group of
Home Tab and choose an option from drop down list.
The simplest way to change the way your text looks is to use Bold, Italics, Underline
button on the formatting tool bar. To apply these, just click the button you want your text to be
formatted into. Formatting text involves Underline, Bold, Italic, and Text in different Fonts, Text
in different font sizes, and text in different colors.
Similarly, you can change the text color, outline and appearance etc.
You can make the lists by using bullets, numbering and multilevel list in the “Paragraph Group”.
1. Select the paragraphs you want to format
2. Click the Home tab on the Ribbon and click the Bullets or Numbering button in the
paragraph group
Click the list arrow on each button to apply a different style of bullets or numbering
40
Figure: 3.4 Bullets
Multileveled lists apply different bullets or numbering to the different levels of a list.
1. Select the paragraphs you want to format
2. Click the Home tab on the Ribbon and click the list arrow on the Multilevel List button in the
paragraph group
41
Figure: 3.6 Paragraph
1. On the home tab of the ribbon, look for the paragraph group. Then click on the Line Spacing
button, as shown in the image below.
Select your desired line spacing. From this menu you can select to have your line spacing set to
1, 1.15, 1.5, 2, 2.5 or 3.
42
Figure: 3.9 Text Direction
After selecting from Text Direction, the text’s direction will be changed on slide.
To change the alignment of text within the text box, follow the following steps;
Select the text. Go to Home tab then in “Paragraph” group.
Click on “Align Text” option. Select any one option.
43
After you select a layout for a SmartArt graphic, the text in your slides is automatically
put in shapes and arranged based on the layout that you chose. You can then customize
the SmartArt graphic by changing its color or by adding a SmartArt style to it.
You can change the colors applied to the shapes in your SmartArt graphic. The different color
combinations are all derived from the theme colors of your presentation.
1. Click the SmartArt graphic.
2. Under SmartArt Tools, on the Design tab, in the SmartArt Styles group, click Change
Colors.
If you don't see the SmartArt Tools or Design tabs, make sure that you've selected a SmartArt
graphic. You may have to double-click the SmartArt graphic to select it and open the Design tab.
The figure shown below states the conversion of the text into SmartArt. It shows how the plain
bulleted text is converted into a professional design.
44
“Drawing” Group of home tab is used to create different type of shapes like square etc.
Shape outline, color and effects can be changed using the same group in Home Tab.
Find Replace option in editing group:
1. On the “Home” tab of the Ribbon, go to the “Editing” group, and select “Find” … or use the
shortcut key CTRL+F.
2. Type the word you want to find, and then press enter.
If you want to make a change to a specific word, you want to use the replace functionality. To
replace a word/s in PowerPoint:
1. Go to the “Editing” group, and select “Replace”, or use the shortcut key CTRL+H
2. In the “Find what” text box, type the word you want to find
3. In the “Replace with” text box, type the word that you want to replace the original word with
4. To replace words one at a time, click “Replace”, if you want to replace every occurrence of
the word in the document, click “Replace All”
Insert Tab
First group in insert tab is “Tables”. On selecting the “table”, different option will appear from
where rows and columns can be selected.
Click on the arrow underneath Table. This will open up a new box with several options
for creating a table.
If you select the Insert Table option, a dialog box will appear where you can enter more
exact specifications for the table.
45
Figure: 3.15 Insert Table
Next group is “Images” group. Any picture placed in any directory of the computer can be
accessed using “Picture” option of this group and can be inserted in slides. Similarly, Clipart can
also be inserted using this group.
It has an option of getting Screenshots. PowerPoint will automatically take the screenshots of
already opened windows and gives the option to select the screenshot and insert in slide.
Click on the. It will give an option to create a new album or edit the existing one.
On clicking the new photo album, the dialogue box is opened
46
Figure: 3.17 Photo Album
On selecting multiple files for album, a new presentation will be generated having all those
selected pictures.
Shapes, SmartArt and charts can be inserted using the “Illustrations” group of the “Insert”
tab. Adding Audio / Video to PowerPoint presentation:
47
Adding Hyperlink:
Select the text or image to link to insert a hyperlink. From right-click menu, click Hyperlink
option
This will bring up Insert Hyperlink dialog, from left side bar, select place in This Document,
from center pane, select a slide to create link with and click OK.
48
Similarly, different equations can be inserted or created in the slide
Task:
49
50
51
52
53
54
Conclusion:
55
EXPERIMENT 04
Objectives
MS Excel is spreadsheet software in the Microsoft Office Suite. Excel allows you to store
manipulate and analyze data in organized workbooks for home and business tasks
56
Opening an Existing Workbook
a. Go to the File Button menu and click on ‘Open’
b. A window appears with some path set (typically ‘My Documents’). The left-hand side of
the window shows some links that allow you to browse through different folders and
change the path
c. Go to the folder where the workbook you want to open is located, select the workbook
and click open
a. Text Alignment
You can left align text
You can right align text
You can center align you text
You can top align text
You can middle align text
You can bottom align you text
b. You can change text orientation, wrap text and merge & center multiple cells as well
57
B. Page Layout Section
This tab is majorly used to set the margins, orientation and background of
the spread sheet.
There is an option “Print Area” in page setup group. By using this option we
can select the area for printing purpose
C. Formula Section
• We can apply different formulas using this tab. Function library group is one of
the mostly used groups
58
Figure: 34.254 Excel worksheet
c) On the Insert tab, in the Charts group, click the chart type that you want to use, and then
click a chart subtype.
59
a. If you want the chart to keep its look and appearance from the Excel
file, select Keep Source Formatting & Link Data
b. If you want the chart to use the look and appearance of the PowerPoint
presentation, select Use Destination Theme & Link Data
f) You can edit chart data in PowerPoint or in Excel by pressing Right Click->Edit Data
99
85
84
30
QTR QTR
1 2
Figure: 34.298 Charts in PowerPoint Special Paste
Task:
60
Write your name and rotate to 270°.
Solution
61
62
63
Tasks:
Do the following tasks
a) Sinusoidal Curves: Generate and plot a 101 sampled sine and a cosine wave of 5
Hz frequency as shown below
•
•
• where = 5 Hz
• ranges from 0 to 1 in step of 0.01
Figure: 34.309
Solution
64
65
66
b) Generate a plot of following polynomials
67
68
69
70
2. Grade sheet
• Create a data that represents the marks obtained by the students in HomeWork#1,
HomeWork#2 and HomeWork#3 (The marks obtained are out of 10 for each
homework)
• Add the data for 10 students, the columns hold categories of the data like:
Students | Name | HW # 1 | HW # 2 | HW # 3
• Apply functions on the data such that
• Fifth column contains the total marks obtained by a student in all the 3
homework.
• Sixth column contains the average of the marks obtained.
• Seventh column contains the percentage.
• Eighth column contains the maximum marks obtained by a student.
• Ninth column contains the minimum marks obtained by a student.
Solution
71
72
73
Conclusion:
74
Experiment 4
Introduction to AI tools for Robotics
Objectives
To become familiar with current AI tools used to program and develop systems for
robotics.
Background
Robotics and artificial intelligence have both been era-defining technologies, and the fusion of both was
nothing short of a revolution. AI in robotics has seen vast success across multiple industries and gained a
significant market over the last few years.
Many organizations integrate AI robots into their routine procedures for increased productivity, efficiency,
and better customer experience. Dominating both tech and non-tech industries, robots can be seen greeting
customers at stores, waiting tables at restaurants, harvesting crops, or lifting heavy loads at manufacturing
plants. In industrial settings, AI-enabled robots keep workers safe by operating in shared spaces. They also
perform complex tasks such as cutting, grinding, welding, and inspection autonomously.
ChatGPT
The most popular AI tool in the current market is ChatGPT, a text-based AI model developed by
OpenAI. One of its standout features is the ChatGPT plugins, particularly designed to enhance
human productivity and efficiency. These versatile plugins find applications across a wide range of
75
domains, including coding, finance, design, and numerous others, delivering top-notch results for
humans.
ChatGPT best features
Flexibility: You can use this AI chatbot for so much more than coding. Because it’s simply a
question-and-response tool, it can streamline workflows across every role in your organization
Follow-up questions: Some AI coding generators fail at the first hurdle by not understanding the
full context of your question. Because ChatGPT asks follow-up questions, it can help you
identify the information you need to provide to get an accurate response
Code review: ChatGPT is particularly adept at identifying errors within your code and helping you
correct them
ChatGPT limitations
Limited context: Some users complain that, in longer conversations, this chatbot has a tendency to
lose the plot. It may forget the information you fed it earlier in the conversation and fail to
provide coherent answers
Generic responses: Some also say this program has a tendency to provide the same boilerplate
responses over and over again, even when the context is different
CodeT5
CodeT5 has a built-in encoder model and a decoder model that allow it to translate natural language
into code (much like ChatGPT) but also to translate code into natural language. So not only can you tell
CodeT5 what to do, but it can tell you what a particular code snippet does. It’s a two-way conversation.
CodeT5 best features
Text-to-code generation: Much like with chatbot AI, you can give CodeT5 a prompt, and it will write
code to match your request
Code-to-code translation: If your team works in multiple program languages, CodeT5 can take your
code in one language, like Python, and translate it into another, like JavaScript
Code summarization: This program can explain what a piece of code does in plain language, which
can help even experienced software developers to learn new languages and frameworks
76
CodeT5 limitations
Possible security risks: The team that designed CodeT5 says that this software might contain sensitive
personal information, like addresses and ID numbers, and it could generate vulnerable code
Google Bard
The top rival of ChatGPT is Google Bard, which is referred as a conversational generative artificial
intelligence chatbot created by Google. Google Bard can chat with people and hold interactive conversations. It
uses advanced AI technologies like LaMDA, PaLM, Imagen, and MusicLM. These technologies are being used
to come up with innovative ways to interact with information, including language, images, videos, and audio,
making the tool quite powerful.
aiXcoder
aiXcoder stands out as the best AI tool for coding, offering the capability to generate code at the method-level
directly from natural language input. It also provides intelligent code completion for entire sections or multiple
lines of code. This tool assist users to seamlessly incorporate suggested code from aiXcoder or continue writing
to receive immediate, contextually-driven feedback.
TabNine
Tabnine serves as an AI code assistant trusted by a global community of over a million developers across
numerous companies. It offers tailored code suggestions that greatly enhance efficiency, simplifying repetitive
coding tasks and yielding top-tier, industry-standard code. Tabnine utilizes a Large Language Model (LLM)
trained on reputable open-source code with permissive licenses, StackOverflow Q&A, and even your entire
codebase (Enterprise feature). This means it generates more relevant, higher quality, more secure code
than ChatGPT 4 or other tools on the market.
SecondBrain
Previously recognized as MagicChat, SecondBrain helps you to construct ChatGPT-like bots equipped with in-
depth familiarity with your business or product, bolstering your sales and customer service initiatives. By
utilizing various content sources such as webpages, files, and documents, you have the capability to train your
bot on how to provide immediate assistance to users visiting your website with inquiries about your services.
77
Lab Task:
78
79
EXPERIMENT 05
Objectives:
To learn about basics of Microsoft Visio and to organize complex ideas visually.
To design flowcharts, choice graphs and network diagrams.
Equipment / Tool:
Background:
Computer diagramming is the process of creating scalable diagrams on a PC that can be used in
various applications such as layout design, organization charts, timelines, floor plans and even
prototype software user interfaces. Diagrams are made of shapes, objects, and stencils, which
when combined correctly, can help project a lot of useful information.
Microsoft Visio is one of the most popular diagramming software that empowers diagramming,
data visualization, and process modelling in a familiar interface. Visio comes with an array of
templates and built-in shapes that allow creating virtually any diagram of any complexity. Visio
also allows users to define their own shapes and import them into the drawing.
The user interface of Visio is like that of other programs in the Office suite. You will be greeted
with a Start page that lists some of the recent documents you have opened along with featured
templates for creating common diagram types. You can also search for templates on the
Microsoft website right from the Start screen.
80
Fig 5.1 Start Screen
81
Visio ─ Creating & Arranging Smart Shapes
Smart Shapes provide contextual shapes which relate to the selected shape.
Start with a blank document (in this case a flowchart diagram). You will notice that the
Shapes pane has different shapes that are applicable to flowcharts.
Click and drag a shape onto the empty canvas. You can resize or rotate the shape as desired.
You can even align the shape with the help of the alignment guides.
When you drag a shape onto the canvas, you will notice that there are four arrows along the
shape.
Click the desired shape to create the shape.
The connections between the shapes are dynamic and they will move in relation to the
placement of the shape.
82
Fig 5.4 Connections between the shapes Fig 5.5 Arranging smart Shapes from data
base
To format shapes, select the shape in the diagram and format using the options available in
the Shape Styles section.
You can select predefined shape styles, or you can customize the shape using the Fill
dropdown menu.
To adjust the color of the shape border, select a color from the Line dropdown menu. The
Effects menu allows to add special effects to your shape such as drop shadows or 3D
rotations.
83
To format a shape outline, click the shape or hold down the Ctrl key on the keyboard and
select multiple shapes.
Then, from the Shape Styles section of the home tab, click Line and select Line Options. This
will open a Format Shape flyout.
In the Line section, select the options you need to customize the shape outline.
You can change the color of the shape outline, increase the width to add more weight, change
the rounding, and a whole lot more. You can also create gradients for the line to suit the
diagram.
84
Fig 5.8 Formatting Connectors
Open the diagram and navigate to the Design tab on the Ribbon.
Click the Re-Layout Page dropdown menu and select a layout as needed.
You will see that the diagram now changes to the selected layout. You can also preview the
look before clicking by hovering the mouse over the layout style.
You can further customize the layout by clicking More Layout Option in the Re-Layout Page
dropdown menu.
This opens a dialog box in which you can configure the layout properties.
85
You can change the spacing between the shapes by manually changing the values in the
Spacing field.
86
To insert a text in a document such as a heading for the chart, click the Text Box
dropdown menu in the Insert tab on the Ribbon and select either horizontal or vertical
text box.
Then place the cursor on the document and draw a text box to start typing.
To format the text, select the text box containing the text or highlight the text itself.
Then, choose from the options available in the Font and Paragraph sections of the home tab.
You can change the font, size, color, and paragraph alignment. If you want to change the font
styles in a shape, just double-click the shape to select the text within the shape and change
the font styles as desired.
87
Visio ─ Inserting Backgrounds
You can change the background of a document by choosing from preset backgrounds or
using your own background template.
To insert a background, click the Background dropdown menu from the Design tab on the
Ribbon and choose a background preset.
This creates a new page in addition to the diagram page.
You can right-click the newly created background page to rename it.
The new background will be automatically applied to all newly created pages in the
document
Visio ─ Themes
Visio allows to customize the theme and overall look of the document.
To apply a theme, go to the Design tab and choose from any of the many theme options
available. You can choose from a selection of Professional, Hand Drawn, Trendy, and
Modern themes.
Once you click any of the available themes, the theme will be applied to the document.
88
The Variants section allows you to customize theme colors as needed.
Clicking the dropdown menu in the Variants section allows to customize the theme colors,
effects, and connectors.
To customize a theme color, go to the Colors submenu in the Variants section and click
Create New Theme Colors.
To insert a hyperlink, first create a text box by going to the Insert tab in the Ribbon and
drawing a horizontal text box for the text that represents the hyperlink such as ‘Website’ or
‘Click here to visit us’.
This text now needs to be converted into a hyperlink. To do so, select the text in the text box
and in the Insert tab again.
Click Link to open the Hyperlinks dialog box. You can specify the links to websites or a
local file on your computer.
Click OK to convert the selected text into a hyperlink.
89
Fig 5.16 Inserting Hyperlink
Lab Task:
90
Solution
Conclusion:
91
EXPERIMENT 06
Objectives
The purpose is to gain fundamental skills to plan the logic of a program by ways of developing
simple logical statements. Whereas ,visual logic is a tool for creating program flowcharts. It
helps to gain fundamental skills to plan the logic of a program by ways of developing an
algorithm in the form of flowchart.
Background
Pseudo code
Pseudo code omits programming level details (like declaration of variables, looping syntax ...)
and so it makes things very easy to understand for human being and implement it in any
programming language easily.
92
EXAMPLE 2:
EXAMPLE 3:
Nesting if statements
93
Visual logic - Background
The programming process follows a program development lifecycle with its initial steps as
understanding the problem and planning the logic. This session focuses on ‘planning the logic’
where we will learn how to develop an algorithm in the form of flowchart
VISUAL LOGIC
SYNTAX
The starting flowchart displays a “Begin” and “End” symbol as shown. To create a flowchart,
you add symbols between these starting symbols.
Hover your mouse over the red arrow between the Begin and End symbols. It will turn green,
indicating that you can click on it to get a popup window. This popup window has the other
symbols we will need to create programs.
94
Figure: 6.5 Visual logic options
Double click on the Output symbol to get the Output dialog box.
Enter your own name and be sure to enclose it within quotes. Later, we will use variables
that don’t use quotes. Click on the “OK” button when done, and the Output symbol will
change to show your intended output. Run the program by clicking on the button on the
toolbar, or by pressing the F5 function key.
95
Example of flowcharts
96
Questions (Pseudocode)
1. Write a Pseudocode. Read in a number and check if the number entered by user is odd or
even.
2. Write a Pseudocode. Read in two numbers, call them A and B. If A is greater than B,
print out A, otherwise print out B.
3. Write a Pseudocode. Read in a number and display the grade of a student.
4. Write a Pseudocode. Read in three numbers, call them A, B and C
If A is bigger than B, then if A is bigger than C, print out A, otherwise print out
C.
If B is bigger than A, then if B is bigger than C, print out B, otherwise print out C.
5. Write a Pseudocode. Display your name and class
6. Write a Pseudocode. Read in the variables and find the area of triangle.
7. Write a Pseudocode. Read in the variables ‘x’ and ‘y’ and get their sum if x>y.
Tasks (Flowchart)
a. Develop the flowchart of a program that takes the radius and height of a cylinder and
calculate its volume
b. Draw flowchart to find the largest among three different numbers entered by user.
c. Develop the flowchart of program to check input characters as vowel or consonants.
d. Develop the flowchart to convert Fahrenheit temperature to Celsius
e. Develop the flowchart that swaps the values in two variables
f. Develop the logic of program to prints out if the number entered is negative
g. Develop a flowchart that sums all the even numbers between 1 and 20, and then
displays the sum
97
1. Write a Pseudocode. Read in a number and check if the number entered by user is odd
or even.
98
99
2. Write a Pseudocode. Read in two numbers, call them A and B. If A is greater than B,
print out A, otherwise print out B.
100
101
3. Write a Pseudocode. Read in a number and display the grade of a student.
102
103
4. Write a Pseudocode. Read in three numbers, call them A, B and C
If A is bigger than B, then if A is bigger than C, print out A, otherwise print
out C.
If B is bigger than A, then if B is bigger than C, print out B, otherwise print
out C.
104
105
5. Write a Pseudocode. Display your name and class
106
6. Write a Pseudocode. Read in the variables and find the area of triangle.
107
108
7. Write a Pseudocode. Read in the variables ‘x’ and ‘y’ and get their sum if x>y.
109
110
a. Develop the flowchart of a program that takes the radius and height of a cylinder
and calculate its volume (V=πr^2 h)
111
112
b. Draw flowchart to find the largest among three different numbers entered by user.
113
c. Develop the flowchart of program to check input characters as vowel or consonants.
114
115
d. Develop the flowchart to convert Fahrenheit temperature to Celsius
116
117
e. Develop the flowchart that swaps the values in two variables
118
119
f. Develop the logic of program to prints out if the number entered is negative
120
g. Develop a flowchart that sums all the even numbers between 1 and 20, and then
displays the sum
121
122
Conclusion:
123
EXPERIMENT 07
Objectives
The purpose of the lab is to get started with the basics of programming language and to get
familiar with debugging the code.
Background
Introduction to C/ C++ Language
C is developed by Dennis Ritchie at AT&T Bell Labs in 1970s which used to maintain UNIX
systems. Many commercial applications are written in C.
C++ was developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s. This overcame
several shortcomings of C. It also incorporated object-oriented programming .C remains a subset
of C++. ‘++’ is an operator in C++.
The Computer Onion
Program Elements
A basic program has following elements:
1) Comments declared as //, /* */
2) Include files
3) Function including exactly one main function
4) Main function contains code or logic of your program being written in programming
language
124
cout is a standard console output stream object.
Used with insertion operator ‘<<‘ to display output on the console.
Insertion operator sends the variable data from its right side to the left side.
cin is a standard console input stream object
Used with the insertion operator ‘>>’ to read any number, character from user
Variables
• Variables are used to hold values
• The values can be of certain types e.g. it can be numbers, characters etc.
• To hold each value uniquely, each variable is initialized with a data
type For example:
int a = 10;
float b = 0.5;
char c = ‘a’;
125
Output
The errors in programming are called bugs. The process of tracking bugs and removing them is
called debugging. Three kinds of errors can occur in a program
1) Syntax Errors
2) Semantic Errors
3) Runtime Errors
1. Syntax Errors: These errors occur when you didn’t follow the syntax of the
programming language. The program will not be compiled if you don’t remove them.
Syntax errors in English language are e.g. Hailo, haow r yeow?
2. Semantic Errors: These are also known as logical errors. The program will compile and
run successfully but it will not do the intended task. This is because there will be an error
in the logic (content) of the program. Debugging logical errors can be tricky because it
requires you to scan the code logically to look for the mistakes. With experience, you will
learn to overcome them easily.
3. Runtime Errors: These errors come at the program execution stage. They are also
known as “Exceptions”. They usually come if the program flow goes out of the expected
order. They are usually rare.
126
Code debugging: It is helpful to detect logical and run time errors from the code. It can also
provide step by step code monitoring. This requires that you add breakpoints at the desired line
of code. Press F11 key to check result at each statement. Press F10 key to execute line of codes
in the current function.
Programming IDE was developed by Microsoft. They used to implement different interactive
software. Visual Studio is an integrated development environment (IDE) that provides a mean to
tell a computer how to do something. Commonly supported languages in VS are: C, C++,
C#.NET and Visual Basic.NET, JavaScript, Python etc.
127
Figure: 7.6 New Project
128
Example
Print “Hello C++ World” in Visual Studio using C++ and debug it
Example
Questions:
a. Develop a program that takes two numbers and display their multiplication and
sum.
b. Develop a program that takes two numbers and display their multiplication
c. Develop the logic and write a program that takes the radius and height of a cylinder
and calculate its volume
d. Develop a program to convert Fahrenheit temperature to Celsius
e. If the marks obtained by a student in five different subjects are input through the
keyboard, write a program to find out the aggregate marks and average marks
obtained by the student. Assume that the maximum marks that can be obtained by a
student in each subject are 100. Take the aggregate sum in ‘int’ and average in float.
Type cast from int to float to take average. Language Allowed: C++
129
1. Develop a program that takes two numbers and display their multiplication and sum.
Solution
130
2. Develop a program that takes two numbers and display their multiplication
Solution
131
132
3. Develop the logic and write a program that takes the radius and height of a cylinder
and calculate its volume
Solution
133
134
4. Develop a program to convert Fahrenheit temperature to Celsius
Solution
135
136
5. If the marks obtained by a student in five different subjects are input through the
keyboard, write a program to find out the aggregate marks and average marks
obtained by the student. Assume that the maximum marks that can be obtained by a
student in each subject are 100. Take the aggregate sum in ‘int’ and average in float.
Type cast from int to float to take average. Language Allowed: C++
Solution
137
Conclusion:
138
EXPERIMENT 08
Objectives
The purpose of the lab is to get familiar with operators more thoroughly and sharpen the skill of
logic development through visual studio C++ programming.
Background
C++ Operators: An operator is simply a symbol that is used to perform operations. There can be
many types of operations like arithmetic, logical, bitwise etc. There are following types of
operators to perform different types of operations in C language.
1) Arithmetic Operators
2) Relational Operators
3) Logical Operators
4) Bitwise Operators
5) Assignment Operator
6) Unary operator
7) Ternary or Conditional Operator
8) Misc Operator
139
Task:
a. The departmental store manager wants a program that calculates and displays the sale
price of a good when its cost price is entered. Sales price is the final price that has 15%
of GST added to cost price. Develop the logic of this program. Languages Allowed: C+
+
Solution
140
b. Body mass index (BMI) is a statistical measurement that compares a person’s weight
and height. To calculate BMI, you multiply your weight in pounds by 703 and divide
the result by the square of your height in inches. Develop the logic for a BMI calculator.
Language: C++
Solution
141
142
c. Develop a program that takes a three-digit number and display the sum of these
numbers. Languages: C++
Solution
143
144
d. Write a program that asks the user to enter a US dollar amount and then shows how to
pay that amount using the smallest number of $20, $10, $5, and $1 bills.
145
Conclusion:
146
EXPERIMENT 093
C/C++ Constructs ,Variable types and memory
Objective:
To familiarize students with the different constructs, variable types and memory usage.
Background:
Most of the code you encounter while learning C can be run using simple text input with text output
directly to a console window. These tutorials will use an empty project configured as a console
application. You can add new source files and code and see the results on the command line.
Here is how you create an empty console project in Visual Studio 2022:
Launch Visual Studio 2022.
In Solution Explorer, right-click Source Files then choose Add, New Item.
147
In Add New Item, choose C File (.c) and then name the file (if file extension is “.cpp” then replace it
with “.c”). Again, the name should reflect the file contents. For example, “HelloWorld” for tutorial code.
Click Add.
Hello World!
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
Press CTRL-F5 to run the program. When you are asked if you want to build it, click Yes. This is the first
time you have run the program, so Visual Studio needs to build it.
Let’s take a closer look. Line numbers have been added for reference and are not part of the program code.
148
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!");
5 return 0;
6}
Line 1: #include <stdio.h> is a header file library that lets us work with input and output functions, such
as printf(() (used in line 4). Header files add functionality to C programs.
Line 2: A blank line. C ignores white space. But we use it to make the code more readable.
Line 3: Another thing that always appear in a C program, is main(). This is called a function. Any code
inside its curly brackets {} will be executed.
Line 4: printf(() is a function used to output/print text to the screen. In our example it will output "Hello
World".
Line 5: return 0 ends the main() function. Every C statement ends with a semicolon;
Line 6: Do not forget to add the closing curly bracket } to actually end the main function.
When we run a compiled program, it is just the already compiled code that is run.
When you compile the code, a .out file is generated, which is then Run to execute the program.
Once a .out file is generated, and then you make any changes to your program in the source code file, you
will have to again compile the code, otherwise, the .out file will have the old source code and will keep
running the old program itself.
In this C tutorial, you created a Visual Studio C console project and created your first C program, Hello
World. Along the way, you learned how C code is built (preprocessor, compile, link), the basic structure
of C applications, and a little bit of C history.
Variables are containers for storing data values, like numbers and characters.
149
In C, there are different types of variables (defined with different keywords), for example:
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
Syntax
Where type is one of C types (such as int), and variableName is the name of the variable (such
as x or myName). The equal sign is used to assign a value to the variable.
So, to create a variable that should store a number, look at the following example:
150
Example
Create a variable called myNum of type int and assign the value 15 to it:
You can also declare a variable without assigning the value, and assign the value later:
// Declare a variable
int myNum;
Output Variables
printf("Hello World!");
In many other programming languages (like Python, Java, and C++), you would normally use a print
function to display the value of a variable. However, this is not possible in C:
Example
To output variables in C, you must get familiar with something called "format specifiers".
Format Specifiers
Format specifiers are used together with the printf() function to tell the compiler what type of data the
variable is storing. It is basically a placeholder for the variable value.
For example, to output the value of an int variable, you must use the format
specifier %d or %i surrounded by double quotes, inside the printf() function:
Example
151
To print other types, use %c for char and %f for float:
Example
// Create variables
int myNum = 15; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character
// Print variables
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);
To combine both text and a variable, separate them with a comma inside the printf() function:
To print different types in a single printf() function, you can use the following:
User Input
Example
int myNum;
152
The scanf() function takes two arguments: the format specifier of the variable (%d in the example above)
and the reference operator (&myNum), which stores the memory address of the variable.
Multiple Inputs
The scanf() function also allow multiple inputs (an integer and a character in the following example):
Example
int myNum;
char myChar;
// Get and save the number AND character the user types
scanf("%d %c", &myNum, &myChar);
C Variable Names
Example
// Good
int minutesPerHour = 60;
Data Types
A variable in C must be a specified data type, and you must use a format specifier inside
the printf() function to display it:
Example
// Create variables
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character
// Print variables
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);
The data type specifies the size and type of information the variable will store.
In this tutorial, we will focus on the most basic ones:
There are different format specifiers for each data type. Here are some of them:
154
Set Decimal Precision
You have probably already noticed that if you print a floating point number, the output will show many
digits after the decimal point:
Example
Lab Tasks:
Lab Task 1: Develop a program that takes two numbers and display their multiplication and sum.
Lab Task 2: Develop a program that takes the length, width and height of a room and calculate its
volume and total surface area and display the results.
155
Lab Task 3: Write a conclusion about what you have learned during this lab.
156
EXPERIMENT 10
Decision Structures (if, if-else, Nested if, Nested if-else, switch statement)
Objectives
The purpose of the lab is to get familiar with decision making conditions through the skill of
logic development using visual studio C++ programming.
Background
There come situations in real life when we need to make some decisions and based on these
decisions, we decide what should we do next. Similar situations arise in programming also where
we need to make some decisions and based on these decisions we will execute the next block of
code.
Decision making statements in programming languages decides the direction of flow of program
execution. Decision making statements available in C++ are:
if statement
if-else statements
nested if statements
if-else-if ladder
switch statements
if statement
if statement is the simplest decision-making statement. It is used to decide whether a certain
statement or block of statements will be executed or not i.e. if a certain condition is true then a
block of statement is executed otherwise not.
Syntax:
if(condition)
{
// Statements to execute if
// condition is true
}
157
if(condition)
statement1;
statement2;
Example:
int main()
{
int i = 10;
if (i > 15)
{
cout<<"10 is less than 15";
}
I am Not in if
As the condition present in the if statement is false. So, the block below the if statement is not
executed.
if- else
The if statement alone tells us that if a condition is true it will execute a block of statements and
if the condition is false it won’t. But what if we want to do something else if the condition is
false. Here comes the else statement. We can use the else statement with if statement to execute a
block of code when the condition is false.
158
Syntax:
if (condition)
{
// Executes this block if
// condition is true
}
else
{
// Executes this block if
// condition is false
}
Example:
int main()
{
int i = 20;
if (i < 15)
cout<<"i is smaller than 15";
else
cout<<"i is greater than 15";
return 0;
}
Run on IDE
Output:
i is greater than 15
The block of code following the else statement is executed as the condition present in
the if statement is false
159
nested-if
A nested if is an if statement that is the target of another if statement. Nested if statements mean
an if statement inside another if statement. Yes, C++ allows us to nest if statements within if
statements. i.e., we can place an if statement inside another if statement.
Syntax:
if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
Example:
// C++ program to illustrate nested-if statement
int main()
{
int i = 10;
if (i == 10)
{
// First if statement
if (i < 15)
cout<<"i is smaller than 15";
// Nested - if statement
// Will only be executed if statement above
// it is true
if (i < 12)
cout<<"i is smaller than 12 too";
else
cout<<"i is greater than 15";
}
return 0;
}
Output:
i is smaller than 15
160
i is smaller than 12 too
if-else-if ladder
Here, a user can decide among multiple options. The if statements are executed from the top
down. As soon as one of the conditions controlling the if is true, the statement associated with
that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then
the final else statement will be executed.
Syntax:
if (condition)
statement;
else if (condition)
statement;
.
.
else
statement;
Example:
// C++ program to illustrate if-else-if ladder
#include<iostream>
using namespace std;
int main()
{
int i = 20;
if (i == 10)
cout<<"i is 10";
else if (i == 15)
cout<<"i is 15";
else if (i == 20)
cout<<"i is 20";
else
cout<<"i is not present";
}
Output:
i is 20
161
Switch Statement in C/C++
Switch case statements are a substitute for long if statements that compare a variable to several
integral values. The switch statement is a multiway branch statement. It provides an easy way to
dispatch execution to different parts of code based on the value of the expression. Switch is a
control statement that allows a value to change control of execution.
Syntax:
switch (n)
{
case 1: // code to be executed if n = 1;
break;
case 2: // code to be executed if n = 2;
break;
default: // code to be executed if n doesn't match any cases
}
162
Nesting of switch statements are allowed, which means you can have switch statements
inside another switch. However nested switch statements should be avoided as it makes
program more complex and less readable.
Example:
// Following is a simple program to demonstrate
// syntax of switch.
#include <stdio.h>
int main()
{
int x = 2;
switch (x)
{
case 1: printf("Choice is 1");
break;
case 2: printf("Choice is 2");
break;
case 3: printf("Choice is 3");
break;
default: printf("Choice other than 1, 2 and 3");
break;
}
return 0;
}
Output:
Choice is 2
Task
a) Write a program that displays the grade of a student where the marks are input from
the keyboard. The grading pattern is as following:
A 85-100
A- 80-84
B+ 75-79
B 71-74
B- 68-70
163
C+ 64-67
C 60-63
C- 57-59
D+ 53-56
D 50-52
F Below 50
W Withdraw
164
b) Write a program for a simple calculator. The program should take two float values and
the operation to be performed (char) from the user. The calculator should perform
addition, subtraction, multiplication, and division. Example execution
Enter first number: 4
Enter Second number: 10
Enter operation to be performed (Select from +, -,*, /): +
Result: 14.
Solution
165
166
c) Write a program for an insurance company that allows only people from a certain age
group to be eligible for a specific insurance scheme. If the age is greater than 45 or less
than 25 it says you are not eligible. Else it prints you are eligible. Language: C++
Solution
167
168
d) The following table shows telephone area codes in the state of Georgia along with the
largest city in each area:
Area code City
229 Albany
404 Atlanta
478 Macon
678 Atlanta
706 Columbus
770 Atlanta
912 Savannah
Write a C++ program that inputs the city area code and prints the corresponding city
name.
Solution
169
e) Write a program that determines the wages of a person based on working hours. If a
person works for less than 5 hours his wage per hour is Rs. 400. If he works for more
than 5 and less than 8 hours wage per hour increases to Rs.560. An addition of Rs. 2000
is given as overtime for workers who work up till 12 hours.
Solution
170
171
f) Use nested loop to print the truth table of three 1-bit inputs
Solution
172
173
g) Write a program that asks the user for a two-digit number (i.e. between 10-99), then
prints the English word for the number:
Enter a two-digit number: 45
You enter the number forty-
five.
Hint: Break the number into two digits. Use one switch statement to print the word for
the first digit (“twenty”, “thirty”, and so forth). Use a second switch statement to print
the word for the second digit. Don’t forget that the numbers between 11 and 19
require special treatment. This needs special attention.
Solution
174
Conclusion:
175
EXPERIMENT # 11
Iterative Structures (For, While, Do-While)
Objective:
To familiarize students with various iterative structures.
Background:
Iterative Structures:
Iterative structures or loops are used to execute multiple statements repeatedly within a program scope.
Every programming language has different set of iterative structures but the most common of them are:
for, while and do-while loops.
While Loop:
While loop executes single or multiple statements until the underlying condition is true.
Example
int i = 0;
while (i < 5) {
printf("%d\n", i);
i++;
}
Do not forget to increase the variable used in the condition (i++), otherwise the loop will never end!
For Loop:
For loop executes single or multiple statements for a fix number of times
176
Example
int i;
Do-while Loop:
Do-while loop executes single or multiple statements at least once whether the underlying condition is
true or false.
Example
int i = 0;
do {
printf("%d\n", i);
i++;
}
while (i < 5);
Do not forget to increase the variable used in the condition, otherwise the loop will never end!
177
Lab Tasks:
Lab Task 1: Print your name for five time on console by using,
For loop
While loop
Lab Task 2: Write a C program to calculate the table of a positive number (generic) using for loop,
output should look like this for number 5.
178
Lab Task 3: Write a C program to calculate the power of entered number.
179
Lab Task 4: Write a C program to calculate the factorial of a number.
Lab Task 5: Write a conclusion about what you have learned during this lab.
180
EXPERIMENT 12
Single Dimension Arrays
Objective:
Background:
Array:
An array is a linear data structure that holds a fixed number of values of a single type. The length of an
array is established when the array is created. After creation, its length is fixed.
Array indices starts from 0, so int X [4] mean: X[0], X[1], X[2], X[3]. Following code shows, how to
input data into array, and how loops help to efficiently deal with arrays. Same as printing array, loops can
also be used to input data in arrays.
Output:
int X[4] = {2,20,15,24};// array
printf("\ti\tx[i]\n");
181
Strings
Example
Access Strings
Since strings are actually arrays in C, you can access a string by referring to its index number inside square
brackets [].
This example prints the first character (0) in greetings:
Example
Note that we have to use the %c format specifier to print a single character.
Modify Strings
To change the value of a specific character in a string, refer to the index number, and use single quotes:
Example
You can also loop through the characters of a string, using a for loop:
Example
182
char carName[] = "Volvo";
int i;
Example
When working with strings in scanf(), you must specify the size of the string/array (we used a very high
number, 30 in our example, but atleast then we are certain it will store enough characters for the first
name), and you don't have to use the reference operator (&).
However, the scanf() function has some limitations: it considers space (whitespace, tabs, etc) as a
terminating character, which means that it can only display a single word (even if you type many words).
Example
char fullName[30];
From the example above, you would expect the program to print "John Doe", but it only prints "John".
That's why, when working with strings, we often use the fgets() function to read a line of text. Note that
you must include the following arguments: the name of the string variable, sizeof(string_name), and stdin:
183
Example
char fullName[30];
Use the scanf() function to get a single word as input, and use fgets() for multiple words.
Lab Tasks:
Lab Task 1: Write a program to copy the contents of one array into another after subtracting one from each
element value.
184
Lab Task 2: Take an array of 10 elements from user. Write a function which can sort all the elements of
the array in ascending or descending order.
Flowchart of Task 2
Lab Task 3:
Create an integer array (int data[10]) and take inputs from the user. Using pointer(or multiple pointers),
change array’s element number 5, 6 and 7 from its original value to squared value, and change array’s
element number 1, 2 and 3 from its original value to zero. Display the whole array after changing values
185
Lab Task 4: Write a conclusion about what you have learned during this lab.
186
Experiment 13
Abstract:
This course lab gives an introduction to the Robot Operating System (ROS) including many of the available
tools that are commonly used in robotics. With the help of different examples, the labcourse should provide a
good starting point for students to work with robots. They learn how to create software including simulation, to
interface sensors and actuators, and to integrate control algorithms.
Objective:
ROS architecture: Master, nodes, topics, messages, services, parameters and actions
Console commands: Navigating and analyzing the ROS system and the catkin workspace
Creating ROS packages: Structure, launch-files, and best practices
ROS C++ client library (roscpp): Creating your own ROS C++ programs
Simulating with ROS: Gazebo simulator, robot models (URDF) and simulation environments (SDF)
Working with visualizations (RViz) and user interface tools (rqt)
Inside ROS: TF transformation system, time, bags
Introduction to ROS2
Content: This course consists of a guided tutorial and exercises with increasing level of difficulty when
working with an autonomous robot. You learn how to setup such a system from scratch using ROS, how to
interface the individual sensors and actuators, and finally how to implement first closed loop control systems.
ROS is becoming the standard in robotics programming, at least in the service robots sector. Initially,
ROS started at universities, but quickly spread into the business world. Every day, more and more
companies and startups are basing their businesses on ROS. Before ROS, every robot had to be
programmed using the manufacturer’s own API. This means that if you changed robots, you had to start
the entire software again, apart from having to learn the new API. Furthermore, you had to know a lot
about how to interact with the electronics of the robot in order to understand how your program was
doing. The situation was similar to that of computers in the 80s, when every computer had its own
187
operating system and you had to create the same program for every type of computer. ROS is for robots
like Windows is for PCs, or Android for phones. By having a ROSified robot, that is, a robot that runs
on ROS, you can create programs that can be shared among different robots. You can build a navigation
program, that is a program to make a robot move around without colliding, for a four-wheeled robot
built by company A and then use the same exact code to move a two-wheeled robot built by company
B… or even use it on a drone from company C, with minor modifications.
Use Cases:
ROS for industrial robots
ROS is being used in many of the service robots that are created at present. On the other side, industrial
robotics companies are still not completely convinced about using it, mainly because they will lose the
power of having a proprietary system. However, four years ago, an international group called ROS-
Industrial (https://rosindustrial.org/) was created, whose aim is to make industrial manufacturers of
robots understand that ROS is for them, since they will be able to use all the software off-the-shelf that
other people have created for other ROS robots.
https://www.theconstructsim.com/ros-for-beginners-how-to-learn-ros/
188
Lab Task:
189
190
Conclusion:
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
___________________________________________________________________________________________________________
191
___________________________________________________________________________________________________________
__________________________________________________________
192
EXPERIMENT 14
224