Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
27 views
SP23 - CSC211 - Data Structures & Algorithms - LAB - W01
Uploaded by
Malik Zohaib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SP23 - CSC211 - Data Structures & Algorithms - LAB... For Later
Download
Save
Save SP23 - CSC211 - Data Structures & Algorithms - LAB... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
27 views
SP23 - CSC211 - Data Structures & Algorithms - LAB - W01
Uploaded by
Malik Zohaib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SP23 - CSC211 - Data Structures & Algorithms - LAB... For Later
Carousel Previous
Carousel Next
Save
Save SP23 - CSC211 - Data Structures & Algorithms - LAB... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 12
Search
Fullscreen
Lab 01 C++ Revision and Array List Objective: In this lab, students will get familiar with the new language C+ and its IDE with the help of simple programs that will clear the syntax of the language. Beside learning the basics of C++ like control statements, functions, arrays, ete., you will also learn the concept of Array List. Activity Outcomes: This lab te © Basic syntax of C++ ches you the following topics: © Data types and operators in C++ © Control flow statements in C++ © Arrays and Functions Instructor Note: As a pre-lab activity, read fundamental concepts from the text book * Deitel, H., Prentice Hall, 2019”. + How to Program, Deitel1) Useful Concepts C+, as we all know is an extension to C language and was developed by Bjarne stroustrup at bell labs. C+ is an intermediate level language, as it comprises a confirmation of both high level and low level language features Following features of C++ makes it a stronger language than C, 1. There is Stronger Type Checking in C+ 2. C+ supports and allows user defined operators (i.e Operator Overloading) and function overloading is also supported init 3. Exception Handling is there in C+ 4, Inline Functions in C++ instead of Macros in C language. Inline functions make complete funtion body act like Macro, safely. ‘Variables can be declared anywhere in the program in C--+, but must be declared before they are used, Installing GNU C/C++ Compiler Install GCC at Windows you need to install MinGW. To install MinGW, go to the MinGW homepage, www.mingw.org, and follow the link to the MinGW download page. Download the latest version of the MinGW installation program which should be named MinGW-
exe, While installing MinGW, at a minimum, you must install gec-core, geo-g++, binutils, and the MinGW runtime, but you may wish to install more, Add the bin subdirectory of your MinGW installation to your PATH environment variable so that ‘you can specify these tools on the command line by their simple names. When the installation is complete, you will be able to run gee, g++, ar, ranlib, diltool, and several other GNU tools from the Windows command line, IDE for coding ‘The IDE we will be using is Dev-C++. Today we will clear our concepts regarding the syntax of C++ with the help of small programs. Note: we use cin for input and cout for output/print At start of your program always use i#include
using namespace std;Shorteut Keys: # Press F10 to compile # Press F9 to run the complied program. * Press F11 to compile and run the program. ‘© For functions in C++ you will have to define them before writing the main method and the main methods always return 0; 2) Solved Lab Activites ‘Allocated Time | Level of Complexity | CLO Mapping Activity T mins Low CLO-4 Activity 2 Smins Low CLO-4 Activity 3 Smins Low CLO-4 mins Tow CLo-4 Activity 5 mins Low CLO-4 Activity 6 Smins Tow CLO-4 Activity 7 F mins Tow CLO-4 Activity 8 S mins Low CLO-4 Activity 9 S mins Tow CLO-4 Activity 10 mins Tow CLO-4 Activity TT Fmins Tow C04 Activity 12 F mins Low CLO-4 Activity 1: ‘Single Line, Multi Line comments and basic Input/Output in C++. Solution:#include
using namespace std; int main() e<<"Hello Wo! return 0; Output ‘The output will be “Hello World!”. Activity 2: Variables are containers for storing data values. In C++, there are different types of variables (defined with different keywords), for example + int stores integers (whole numbers), without decimals, such as 123 ot -123 + double - stores floating point numbers, with decimals, such as 19.99 or -19.99 + char - stores single characters, such as '' or 'B', Char values are surrounded by single quotes + string - stores text, such as "Hello World’, String values are surrounded by double quotes + bool - stores values with two states: true or false Solution: Finclude
using namespace std; int main () { tial value undetermined‘Output Value present in result variable will be shown on Screen Activity 3: Using cin, extraction operator (>>) and cout (<<). cin iJava program to illustrate enhanced for loop mespace int main () a> stds a) number: "; // xe // Get user" input "Your numbe: ‘splay the input keyboard Output ‘Type a number: 100 ‘Your number is: 100 suppose user enters 100string mystring; different string conte return 0; jal string content ‘This is a different string content Activity 5: Write a program to use arithmetic operators in C++ Finclade
int main () ana; // equivalent to a-at2 OutputAc ity 6: Write a program to use relational operators in C++ bas (@b) 2a: be cout << ¢ << "n'y Output 7 Activity 7: Write a program to use if-else statement in C++ Finclude
int main () int x7 cin>>xs if (x > 0) cout << "% i else if (x < 0) cout << Mx ds 10Output ‘The ouput depends upon the value of “x’ entered by the user, the output will be either x is positive or xis negative or xis 0. Act ity 8: Write a program to use while loop in C++ while (n>0) { cout
using namespace std; int main () { string str; do { cout << "Enter text: "7 getline (cin,str); cout << "You entered: " << str << "\n'y J while (str != "goodbye") ; ‘Output Program repeatedly takes a string as input then displays it say! types goodbye. Activity 10: Write a program to apply the switch statements. 1g “You entered...” Until user Finclude
using namespace std; int main () break; case 2 << "Tuesday"; case 3: ‘cout. << break; tiiednesday"; 2rsday", "ppiday"; Saturday"; Output Outputs "Thursday" as variable day is Activity 11: Write a program that will add two numbers in a function and call that function in main. Finclade
int addition (int a, int b) 2 = addition (5, cout << "The result is "<< 2; BOutput ‘The result is 8 Activity 12: Write a program to use the concept of Arrays in C++ Finclude
using namespace std; int foo {] = {16, 2, 77, 40, 12071}; int n, result=0; cout << result, ‘Output 12206 3) Graded Lab Tasks Note: The instructor can design graded lab activities according to the level of difficulty and complexity of the solved lab activities, The lab tasks assigned by the instructor should be evaluated in the same lab Lab Task 1 Write down a program that find [X° , where input for X and starting and stopping value is entered by the user. 14Lab Task 2 Write the computer program to apply the concepts of Array List. The array list will include the following fimetions Insert the value at end of the list Insert the value at start ofthe list Insert the value after specific value Insert the value before specific value Display the array list Delete the value from end of the list Delete the value from start of the list Delete specific value Lab Task 3 Using, while loop apply liear search on the Array List you developed in Lab Task 2. 15
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Victoria Walters
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
Graphs Intro + Shortest Path + Traversal
PDF
No ratings yet
Graphs Intro + Shortest Path + Traversal
49 pages
Structural Modeling
PDF
No ratings yet
Structural Modeling
60 pages
Hashing Updated
PDF
No ratings yet
Hashing Updated
26 pages
Assignment 1
PDF
No ratings yet
Assignment 1
10 pages
Binary Trees
PDF
No ratings yet
Binary Trees
28 pages
SEC Assignment # 2
PDF
No ratings yet
SEC Assignment # 2
14 pages
AVL Trees
PDF
No ratings yet
AVL Trees
31 pages
Activity
PDF
No ratings yet
Activity
6 pages
Comsat S University Islamabad: Course Title: Course Name: Lab: Group Members
PDF
No ratings yet
Comsat S University Islamabad: Course Title: Course Name: Lab: Group Members
3 pages
Melds Apparatus
PDF
100% (1)
Melds Apparatus
4 pages
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
Graphs Intro + Shortest Path + Traversal
PDF
Graphs Intro + Shortest Path + Traversal
Structural Modeling
PDF
Structural Modeling
Hashing Updated
PDF
Hashing Updated
Assignment 1
PDF
Assignment 1
Binary Trees
PDF
Binary Trees
SEC Assignment # 2
PDF
SEC Assignment # 2
AVL Trees
PDF
AVL Trees
Activity
PDF
Activity
Comsat S University Islamabad: Course Title: Course Name: Lab: Group Members
PDF
Comsat S University Islamabad: Course Title: Course Name: Lab: Group Members
Melds Apparatus
PDF
Melds Apparatus
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel