The document discusses functions in C++. It defines functions as modular pieces that divide programs into more manageable components. It describes function components like modules, functions, classes, and function calls. It provides examples of math library functions and how to define, call, and prototype functions. It also covers function parameters, return types, and scope rules for local variables and storage classes.
The document discusses different types of storage classes in C++ that determine the lifetime and scope of variables:
1. Local variables are defined inside functions and have scope limited to that function. They are destroyed when the function exits.
2. Global variables are defined outside all functions and have scope in the entire program. They are destroyed when the program ends.
3. Static local variables are local variables that retain their value between function calls. Register variables are local variables stored in processor registers for faster access.
4. Thread local storage allows defining variables that are local to each thread and retain their values similar to static variables. The document provides examples to illustrate local, global, and static variables.
This document discusses different types of functions in C++, including user-defined functions, library functions, function parameters, return values, function prototypes, and function overloading. It provides examples to illustrate key concepts like defining functions with different parameters and return types, passing arguments to functions, and returning values from functions. Storage classes like local, global, static local and register variables are also briefly covered. The document is an introduction to functions in C++ programming.
This document provides an introduction to C++ programming. It covers basic concepts like variables, data types, input/output statements, conditional statements, loops, arrays, functions, and classes. Some key points:
- A C++ program consists of variable declarations, input/output statements, computations, and printing output. Comments begin with //.
- Variables are declared with a data type like int or double followed by the name. Input is done with cin and output with cout.
- Conditional statements like if-else and loops like while are used to control program flow. Boolean conditions use comparison and logical operators.
- Arrays allow storing multiple values of a type. Functions can be predefined or programmer-
The document discusses various string handling, mathematical, and random number generation functions available in C++ library. It provides examples of functions like strlen(), strcpy(), strcmp(), sqrt(), pow(), randomize(), random(). It also provides programs to demonstrate the use of these functions for tasks like checking palindromes, searching strings, toggling case, generating random numbers in a given range.
The document discusses functions and function components in C++. It introduces key concepts such as:
- Functions allow programmers to divide programs into modular and reusable pieces.
- Functions are defined once and can be called multiple times from different parts of a program. They take in parameters and return values.
- The standard library provides many commonly used functions for tasks like math operations.
- Functions can be used to encapsulate and reuse code through prototypes and definitions.
- Enumerations allow defining a set of integer constants with unique names for use as variable types.
- Storage classes like static and auto determine where variables are stored in memory and their scope within a program.
The document discusses functions in C++. It begins by outlining key topics about functions that will be covered, such as function definitions, standard library functions, and function calls. It then provides details on defining and calling functions, including specifying return types, parameters, function prototypes, scope rules, and passing arguments by value or reference. The document also discusses local and global variables, function errors, and the differences between calling functions by value or reference.
The document provides instructions for a C++ programming assignment involving functions, pointers, arrays, and calculating pi. It includes 6 problems to solve:
1. Write functions to demonstrate default arguments, constant arguments, and random number generation.
2. Analyze sample code and identify errors in provided code snippets.
3. Write functions to calculate sums of various data types.
4. Use a Monte Carlo simulation to approximate pi by simulating dart throws on a circle and square.
5. Write functions to print, reverse, and transpose arrays.
6. Write functions to operate on strings and pointers.
C++ functions allow programmers to organize code into reusable blocks to perform specific tasks. There are two types of functions: standard library functions that are predefined in C++, and user-defined functions that are created by programmers. User-defined functions in C++ are declared with a return type, function name, and parameters. Functions can return values using the return statement. Function prototypes allow functions to be defined after they are called. Functions improve code readability and reusability.
The document provides guidance on various programming concepts, specifically targeting C++ programming assignments. It covers topics like function prototypes, global variables, random number generation, function overloading, templates, recursion, Pascal's triangle, and array manipulation. Additionally, it offers examples and exercises aimed at enhancing understanding of these concepts.
Programming For Engineers Functions - Part #1.pptxNoorAntakia
This document discusses functions in C++ programming. It begins by explaining the objectives of learning about standard predefined functions, user-defined functions, value-returning functions, and constructing user-defined functions. It then provides examples of user-defined functions for finding the maximum of two numbers, checking if a number is prime, calculating the nth Fibonacci number, and calculating binomial coefficients. It also discusses concepts like function prototypes, parameters, return types, and using functions to break programs into manageable pieces.
This document discusses value-returning functions in C++. It covers built-in functions like pow(), sqrt(), rand(), and time() as well as creating user-defined value-returning functions. Examples include programs to calculate a hypotenuse using pow() and sqrt(), generate random numbers with rand() and srand(), and a guessing game to demonstrate function calls. The chapter explains how to define and call value-returning functions, pass arguments by value, and return values from functions.
6. Functions in C ++ programming object oriented programmingAhmad177077
The document provides a comprehensive overview of functions in C++, covering their definitions, structures, types, and various mechanisms such as recursion and function overloading. It explains the importance of functions in promoting code reusability, modular coding, and abstraction. Key topics include different ways to pass parameters (by value and by reference), inline functions, and examples of function overloading.
This document provides an overview of functions in C++ programming, detailing their definition, components, and calling mechanisms. It explains the difference between built-in and user-defined functions, showcases various types of function parameters, and emphasizes the importance of function prototypes and scopes. Additionally, it includes examples illustrating function implementation and usage in code.
This document is a lecture on programming fundamentals, focusing on functions in C++. It covers the types, declaration, definition, and the importance of functions, as well as examples of built-in and user-defined functions. Additionally, it explains concepts such as 'call by value' and 'call by reference' with corresponding code snippets.
This document outlines the contents of Chapter 3 from a textbook on functions in C++. It discusses key concepts about functions including definitions, prototypes, parameters, return types, scope, recursion, and more. Specific examples are provided to demonstrate defining and calling simple functions to calculate values like squares, find maximums, and generate random numbers by rolling dice. The chapter aims to explain the modular nature of breaking programs into smaller, reusable functions.
The document discusses the structure and usage of C++ functions, covering standard and user-defined functions, their syntax, and the role of function signatures. It elaborates on how to share data among functions using parameters and global variables, while outlining best practices for defining and implementing functions. Additionally, it emphasizes the importance of information hiding and provides examples of function declarations and implementations.
power point presentation on object oriented programming functions conceptsbhargavi804095
The document discusses C++ functions. It covers the following key points in 3 sentences:
Standard functions that are included with C++ like math functions are discussed as well as how to define user-defined functions. User-defined functions are defined with a function header, parameters, and body. Functions can share data through parameters, either by value or by reference, and variables can have local or global scope.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
This document discusses C++ functions. It defines standard functions that come with C++ and user-defined functions. It explains the structure of a C++ function including the function header and body. It discusses declaring function signatures separately from implementations. Parameters and scopes are also covered. Examples are provided of standard math and character functions as well as user-defined functions. Header files for organizing function declarations and implementation files are demonstrated.
This document outlines the contents of Chapter 3 - Functions from a C++ textbook. It discusses key concepts about functions including defining and calling functions, function parameters and return values, function prototypes, header files, and random number generation using functions. Example code is provided to demonstrate creating, calling, and using functions to perform tasks like calculating squares, finding maximums, and simulating dice rolls.
This document contains a summary of a lecture on C++ functions:
- It discusses function parameters, return types, and calling functions. It provides an example function that prints the "99 bottles" song lyrics.
- Debugging functions using an IDE like Qt Creator is explained. The importance of function declaration order is also covered.
- Pre-written math functions from the <cmath> library are introduced as an alternative to writing functions like square root from scratch.
The document is a report on the topic of computer programming and utilization prepared by group C. It discusses functions, including the definition of a function, function examples, benefits of functions, function prototypes, function arguments, and recursion. It provides examples of math library functions, global and local variables, and external variables. It also includes examples of recursive functions to calculate factorials and the Fibonacci series recursively.
The document discusses user-defined functions in C++. It explains that functions help divide programs into smaller, more manageable pieces. Functions are defined with a return type, parameter list, and function body. Functions are called by name with arguments in parentheses. Parameters allow functions to access external information. Function prototypes specify the signature of the function. Functions can return values or be defined as void if they do not return anything.
The document discusses user-defined functions in C++. It explains that functions help divide programs into smaller, more manageable pieces. Functions are defined with a return type, parameter list, and function body. Functions can take arguments and return values. Function prototypes specify the function signature. Functions can be called by name and passed arguments. Global variables are accessible everywhere while local variables are only accessible within their function.
The document discusses functions in C++. It begins by showing an example of copying and pasting code to compute 3^4 and 6^5, which is inefficient. It then demonstrates defining a function called raiseToPower() that takes a base and exponent as arguments and computes the power in a reusable way. The document explains the syntax of defining functions, including the return type, arguments, body, and return statement. It also covers topics like function overloading, function prototypes, recursion, and global versus local variables.
How to Implement Least Package Removal Strategy in Odoo 18 InventoryCeline George
In Odoo, the least package removal strategy is a feature designed to optimize inventory management by minimizing the number of packages open to fulfill the orders. This strategy is particularly useful for the business that deals with products packages in various quantities such as boxes, cartons or palettes.
More Related Content
Similar to Chp7_C++_Functions_Part1_Built-in functions.pptx (20)
The document provides instructions for a C++ programming assignment involving functions, pointers, arrays, and calculating pi. It includes 6 problems to solve:
1. Write functions to demonstrate default arguments, constant arguments, and random number generation.
2. Analyze sample code and identify errors in provided code snippets.
3. Write functions to calculate sums of various data types.
4. Use a Monte Carlo simulation to approximate pi by simulating dart throws on a circle and square.
5. Write functions to print, reverse, and transpose arrays.
6. Write functions to operate on strings and pointers.
C++ functions allow programmers to organize code into reusable blocks to perform specific tasks. There are two types of functions: standard library functions that are predefined in C++, and user-defined functions that are created by programmers. User-defined functions in C++ are declared with a return type, function name, and parameters. Functions can return values using the return statement. Function prototypes allow functions to be defined after they are called. Functions improve code readability and reusability.
The document provides guidance on various programming concepts, specifically targeting C++ programming assignments. It covers topics like function prototypes, global variables, random number generation, function overloading, templates, recursion, Pascal's triangle, and array manipulation. Additionally, it offers examples and exercises aimed at enhancing understanding of these concepts.
Programming For Engineers Functions - Part #1.pptxNoorAntakia
This document discusses functions in C++ programming. It begins by explaining the objectives of learning about standard predefined functions, user-defined functions, value-returning functions, and constructing user-defined functions. It then provides examples of user-defined functions for finding the maximum of two numbers, checking if a number is prime, calculating the nth Fibonacci number, and calculating binomial coefficients. It also discusses concepts like function prototypes, parameters, return types, and using functions to break programs into manageable pieces.
This document discusses value-returning functions in C++. It covers built-in functions like pow(), sqrt(), rand(), and time() as well as creating user-defined value-returning functions. Examples include programs to calculate a hypotenuse using pow() and sqrt(), generate random numbers with rand() and srand(), and a guessing game to demonstrate function calls. The chapter explains how to define and call value-returning functions, pass arguments by value, and return values from functions.
6. Functions in C ++ programming object oriented programmingAhmad177077
The document provides a comprehensive overview of functions in C++, covering their definitions, structures, types, and various mechanisms such as recursion and function overloading. It explains the importance of functions in promoting code reusability, modular coding, and abstraction. Key topics include different ways to pass parameters (by value and by reference), inline functions, and examples of function overloading.
This document provides an overview of functions in C++ programming, detailing their definition, components, and calling mechanisms. It explains the difference between built-in and user-defined functions, showcases various types of function parameters, and emphasizes the importance of function prototypes and scopes. Additionally, it includes examples illustrating function implementation and usage in code.
This document is a lecture on programming fundamentals, focusing on functions in C++. It covers the types, declaration, definition, and the importance of functions, as well as examples of built-in and user-defined functions. Additionally, it explains concepts such as 'call by value' and 'call by reference' with corresponding code snippets.
This document outlines the contents of Chapter 3 from a textbook on functions in C++. It discusses key concepts about functions including definitions, prototypes, parameters, return types, scope, recursion, and more. Specific examples are provided to demonstrate defining and calling simple functions to calculate values like squares, find maximums, and generate random numbers by rolling dice. The chapter aims to explain the modular nature of breaking programs into smaller, reusable functions.
The document discusses the structure and usage of C++ functions, covering standard and user-defined functions, their syntax, and the role of function signatures. It elaborates on how to share data among functions using parameters and global variables, while outlining best practices for defining and implementing functions. Additionally, it emphasizes the importance of information hiding and provides examples of function declarations and implementations.
power point presentation on object oriented programming functions conceptsbhargavi804095
The document discusses C++ functions. It covers the following key points in 3 sentences:
Standard functions that are included with C++ like math functions are discussed as well as how to define user-defined functions. User-defined functions are defined with a function header, parameters, and body. Functions can share data through parameters, either by value or by reference, and variables can have local or global scope.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
This document discusses C++ functions. It defines standard functions that come with C++ and user-defined functions. It explains the structure of a C++ function including the function header and body. It discusses declaring function signatures separately from implementations. Parameters and scopes are also covered. Examples are provided of standard math and character functions as well as user-defined functions. Header files for organizing function declarations and implementation files are demonstrated.
This document outlines the contents of Chapter 3 - Functions from a C++ textbook. It discusses key concepts about functions including defining and calling functions, function parameters and return values, function prototypes, header files, and random number generation using functions. Example code is provided to demonstrate creating, calling, and using functions to perform tasks like calculating squares, finding maximums, and simulating dice rolls.
This document contains a summary of a lecture on C++ functions:
- It discusses function parameters, return types, and calling functions. It provides an example function that prints the "99 bottles" song lyrics.
- Debugging functions using an IDE like Qt Creator is explained. The importance of function declaration order is also covered.
- Pre-written math functions from the <cmath> library are introduced as an alternative to writing functions like square root from scratch.
The document is a report on the topic of computer programming and utilization prepared by group C. It discusses functions, including the definition of a function, function examples, benefits of functions, function prototypes, function arguments, and recursion. It provides examples of math library functions, global and local variables, and external variables. It also includes examples of recursive functions to calculate factorials and the Fibonacci series recursively.
The document discusses user-defined functions in C++. It explains that functions help divide programs into smaller, more manageable pieces. Functions are defined with a return type, parameter list, and function body. Functions are called by name with arguments in parentheses. Parameters allow functions to access external information. Function prototypes specify the signature of the function. Functions can return values or be defined as void if they do not return anything.
The document discusses user-defined functions in C++. It explains that functions help divide programs into smaller, more manageable pieces. Functions are defined with a return type, parameter list, and function body. Functions can take arguments and return values. Function prototypes specify the function signature. Functions can be called by name and passed arguments. Global variables are accessible everywhere while local variables are only accessible within their function.
The document discusses functions in C++. It begins by showing an example of copying and pasting code to compute 3^4 and 6^5, which is inefficient. It then demonstrates defining a function called raiseToPower() that takes a base and exponent as arguments and computes the power in a reusable way. The document explains the syntax of defining functions, including the return type, arguments, body, and return statement. It also covers topics like function overloading, function prototypes, recursion, and global versus local variables.
How to Implement Least Package Removal Strategy in Odoo 18 InventoryCeline George
In Odoo, the least package removal strategy is a feature designed to optimize inventory management by minimizing the number of packages open to fulfill the orders. This strategy is particularly useful for the business that deals with products packages in various quantities such as boxes, cartons or palettes.
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...RAKESH SAJJAN
This PowerPoint presentation is based on Unit 7 – Assisting Individuals and Families to Promote and Maintain Their Health, a core topic in Community Health Nursing – I for 5th Semester B.Sc Nursing students, as per the Indian Nursing Council (INC) guidelines.
The unit emphasizes the nurse’s role in family-centered care, early detection of health problems, health promotion, and appropriate referrals, especially in the context of home visits and community outreach. It also strengthens the student’s understanding of nursing responsibilities in real-life community settings.
📘 Key Topics Covered in the Presentation:
Introduction to family health care: needs, principles, and objectives
Assessment of health needs of individuals, families, and groups
Observation and documentation during home visits and field assessments
Identifying risk factors: environmental, behavioral, genetic, and social
Conducting growth and development monitoring in infants and children
Recording and observing:
Milestones of development
Menstrual health and reproductive cycle
Temperature, blood pressure, and vital signs
General physical appearance and personal hygiene
Social assessment: understanding family dynamics, occupation, income, living conditions
Health education and counseling for individuals and families
Guidelines for early detection and referral of communicable and non-communicable diseases
Maintenance of family health records and individual health cards
Assisting families with:
Maternal and child care
Elderly and chronic disease management
Hygiene and nutrition guidance
Utilization of community resources – referral linkages, support services, and local health programs
Role of nurse in coordinating care, advocating for vulnerable individuals, and empowering families
Promoting self-care and family participation in disease prevention and health maintenance
This presentation is highly useful for:
Nursing students preparing for internal exams, university theory papers, or community postings
Health educators conducting family teaching sessions
Students conducting fieldwork and project work during community postings
Public health nurses and outreach workers dealing with preventive, promotive, and rehabilitative care
It’s structured in a step-by-step format, featuring tables, case examples, and simplified explanations tailored for easy understanding and classroom delivery.
This presentation was provided by Jennifer Gibson of Dryad, during the second session of our 2025 NISO training series "Secrets to Changing Behavior in Scholarly Communications." Session Two was held June 12, 2025.
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...parmarjuli1412
SCHIZOPHRENIA INCLUDED TOPIC IS INTRODUCTION, DEFINITION OF GENERAL TERM IN PSYCHIATRIC, THEN DIFINITION OF SCHIZOPHRENIA, EPIDERMIOLOGY, ETIOLOGICAL FACTORS, CLINICAL FEATURE(SIGN AND SYMPTOMS OF SCHIZOPHRENIA), CLINICAL TYPES OF SCHIZOPHRENIA, DIAGNOSIS, INVESTIGATION, TREATMENT MODALITIES(PHARMACOLOGICAL MANAGEMENT, PSYCHOTHERAPY, ECT, PSYCHO-SOCIO-REHABILITATION), NURSING MANAGEMENT(ASSESSMENT,DIAGNOSIS,NURSING INTERVENTION,AND EVALUATION), OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndrome(The Delusion of Doubles)/Acute and Transient Psychotic Disorders/Induced Delusional Disorders/Schizoaffective Disorder /CAPGRAS SYNDROME(DELUSION OF DOUBLE), GERIATRIC CONSIDERATION, FOLLOW UP, HOMECARE AND REHABILITATION OF THE PATIENT,
Health Care Planning and Organization of Health Care at Various Levels – Unit...RAKESH SAJJAN
This comprehensive PowerPoint presentation is prepared for B.Sc Nursing 5th Semester students and covers Unit 2 of Community Health Nursing – I based on the Indian Nursing Council (INC) syllabus. The unit focuses on the planning, structure, and functioning of health care services at various levels in India. It is especially useful for nursing educators and students preparing for university exams, internal assessments, or professional teaching assignments.
The content of this presentation includes:
Historical development of health planning in India
Detailed study of various health committees: Bhore, Mudaliar, Kartar Singh, Shrivastava Committee, etc.
Overview of major health commissions
In-depth understanding of Five-Year Plans and their impact on health care
Community participation and stakeholder involvement in health care planning
Structure of health care delivery system at central, state, district, and peripheral levels
Concepts and implementation of Primary Health Care (PHC) and Sustainable Development Goals (SDGs)
Introduction to Comprehensive Primary Health Care (CPHC) and Health and Wellness Centers (HWCs)
Expanded role of Mid-Level Health Providers (MLHPs) and Community Health Providers (CHPs)
Explanation of national health policies: NHP 1983, 2002, and 2017
Key national missions and schemes including:
National Health Mission (NHM)
National Rural Health Mission (NRHM)
National Urban Health Mission (NUHM)
Ayushman Bharat – Pradhan Mantri Jan Arogya Yojana (PM-JAY)
Universal Health Coverage (UHC) and India’s commitment to equitable health care
This presentation is ideal for:
Nursing students (B.Sc, GNM, Post Basic)
Nursing tutors and faculty
Health educators
Competitive exam aspirants in nursing and public health
It is organized in a clear, point-wise format with relevant terminologies and a focus on applied knowledge. The slides can also be used for community health demonstrations, teaching sessions, and revision guides.
BLUF:
The Texas outbreak has slowed down, but sporadic cases continue to emerge in Kansas, Oklahoma, and New Mexico.
Elsewhere in the US, we continue to see signs of acceleration due to outbreaks outside the Southwest (North Dakota, Montana, and Colorado) and travel-related cases. Measles exposures due to travel are expected to pose a significant challenge throughout the summer.
The U.S. is on track to exceed its 30-year high for measles cases (1,274) within the next two weeks.
Here is the latest update:
CURRENT CASE COUNT: 919
•Texas: 744 (+2) (55% of cases are in Gaines County).
•New Mexico: 81 (83% of cases are from Lea County).
•Oklahoma: 20 (+2)
•Kansas: 74 (+5) (38.89% of the cases are from Gray County).
HOSPITALIZATIONS: 104
• Texas: 96 (+2) – This accounts for 13% of all cases in Texas.
• New Mexico: 7 – This accounts for 9.47% of all cases in New Mexico.
• Kansas: 3 – This accounts for 5.08% of all cases in the state of Kansas.
DEATHS: 3
•Texas: 2 – This is 0.27% of all cases in Texas.
•New Mexico: 1 – This is 1.23% of all cases in New Mexico.
US NATIONAL CASE COUNT: 1,197
INTERNATIONAL SPREAD
•Mexico: 2337 (+257), 5 fatalities
‒Chihuahua, Mexico: 2,179 (+239) cases, 4 fatalities, 7 currently hospitalized.
•Canada: 3,207 (+208), 1 fatality
‒Ontario Outbreak, Canada: 2,115 (+74) cases, 158 hospitalizations, 1 fatality.
‒Alberta, Canada: 879(+118) cases, 5 currently hospitalized.
Introduction to Generative AI and Copilot.pdfTechSoup
In this engaging and insightful two-part webinar series, where we will dive into the essentials of generative AI, address key AI concerns, and demonstrate how nonprofits can benefit from using Microsoft’s AI assistant, Copilot, to achieve their goals.
This event series to help nonprofits obtain Copilot skills is made possible by generous support from Microsoft.
See our 2 Starter PDFs within a Compressed, Zip Drive. Within Shop. Videos will be available Before the Weekend of 6/14th. For the US, Happy Fathers Day Weekend. (Our readers/teams are global.) Also, our content remains timeless for Future Grad Students seeking updates.
After about a Year or 10, I retire older content. Literally up to under 10 yrs. We will be 19 yrs old this Aug for Love and Divinity in Motion (LDM). How old are we? So funny. Our oldest profile is X, formerly Twitter. From our old Apple Podcast Years.
https://ldm-mia.creator-spring.com
Session/Lesson 1 -Intro
REIKI- YOGA “ORIENTATION”
It helps to understand the text behind anything. This improves our performance and confidence.
Your training will be mixed media. Includes Rehab Intro and Meditation vods, all sold separately.
Editing our Vods & New Shop. Retail under $30 per item.
*Store Fees will apply. *Digital Should be low cost.
Thank you for attending our free workshops. Those can be used with any Reiki Yoga training package. Traditional Reiki does host rules and ethics. Its silent and within the JP Culture/Area/Training/Word of Mouth. It allows remote healing but there’s limits for practitioners and masters. We are not allowed to share certain secrets/tools. Some content is designed only for “Masters”...
Next Upload will be our Video package for Session 1. Prices will be affordable as possible. Thx for becoming a "Practitioner Level" Student.
Updates so far, are every week for spring. Summer should be a similar schedule. Thx for visitings, attending, and following LDMMIA.
Social Media:
https://x.com/OnlineDrLeZ
and
https://www.instagram.com/chelleofsl/
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil DisobedienceRajdeep Bavaliya
Dive into the powerful journey from Thoreau’s 19th‑century essay to Gandhi’s mass movement, and discover how one man’s moral stand became the backbone of nonviolent resistance worldwide. Learn how conscience met strategy to spark revolutions, and why their legacy still inspires today’s social justice warriors. Uncover the evolution of civil disobedience. Don’t forget to like, share, and follow for more deep dives into the ideas that changed the world.
M.A. Sem - 2 | Presentation
Presentation Season - 2
Paper - 108: The American Literature
Submitted Date: April 2, 2025
Paper Name: The American Literature
Topic: Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
[Please copy the link and paste it into any web browser to access the content.]
Video Link: https://youtu.be/HXeq6utg7iQ
For a more in-depth discussion of this presentation, please visit the full blog post at the following link: https://rajdeepbavaliya2.blogspot.com/2025/04/thoreau-s-influence-on-gandhi-the-evolution-of-civil-disobedience.html
Please visit this blog to explore additional presentations from this season:
Hashtags:
#CivilDisobedience #ThoreauToGandhi #NonviolentResistance #Satyagraha #Transcendentalism #SocialJustice #HistoryUncovered #GandhiLegacy #ThoreauInfluence #PeacefulProtest
Keyword Tags:
civil disobedience, Thoreau, Gandhi, Satyagraha, nonviolent protest, transcendentalism, moral resistance, Gandhi Thoreau connection, social change, political philosophy
This is complete for June 17th. For the weekend of Summer Solstice
June 20th-22nd.
6/17/25: “My now Grads, You’re doing well. I applaud your efforts to continue. We all are shifting to new paradigm realities. Its rough, there’s good and bad days/weeks. However, Reiki with Yoga assistance, does work.”
6/18/25: "For those planning the Training Program Do Welcome. Happy Summer 2k25. You are not ignored and much appreciated. Our updates are ongoing and weekly since Spring. I Hope you Enjoy the Practitioner Grad Level. There's more to come. We will also be wrapping up Level One. So I can work on Levels 2 topics. Please see documents for any news updates. Also visit our websites. Every decade I release a Campus eMap. I will work on that for summer 25. We have 2 old libraries online thats open. https://ldmchapels.weebly.com "
Your virtual attendance is appreciated. No admissions or registration needed.
We hit over 5k views for Spring Workshops and Updates-TY.
As a Guest Student,
You are now upgraded to Grad Level.
See Uploads for “Student Checkins” & “S9”. Thx.
Happy Summer 25.
These are also timeless.
Thank you for attending our workshops.
If you are new, do welcome.
For visual/Video style learning see our practitioner student status.
This is listed under our new training program. Updates ongoing levels 1-3 this summer. We just started Session 1 for level 1.
These are optional programs. I also would like to redo our library ebooks about Hatha and Money Yoga. THe Money Yoga was very much energy healing without the Reiki Method. An updated ebook/course will be done this year. These Projects are for *all fans, followers, teams, and Readers. TY for being presenting.
Pests of Maize: An comprehensive overview.pptxArshad Shaikh
Maize is susceptible to various pests that can significantly impact yields. Key pests include the fall armyworm, stem borers, cob earworms, shoot fly. These pests can cause extensive damage, from leaf feeding and stalk tunneling to grain destruction. Effective management strategies, such as integrated pest management (IPM), resistant varieties, biological control, and judicious use of chemicals, are essential to mitigate losses and ensure sustainable maize production.
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...Ultimatewinner0342
🧠 Lazy Sunday Quiz | General Knowledge Trivia by SMC Quiz Club – Silchar Medical College
Presenting the Lazy Sunday Quiz, a fun and thought-provoking general knowledge quiz created by the SMC Quiz Club of Silchar Medical College & Hospital (SMCH). This quiz is designed for casual learners, quiz enthusiasts, and competitive teams looking for a diverse, engaging set of questions with clean visuals and smart clues.
🎯 What is the Lazy Sunday Quiz?
The Lazy Sunday Quiz is a light-hearted yet intellectually rewarding quiz session held under the SMC Quiz Club banner. It’s a general quiz covering a mix of current affairs, pop culture, history, India, sports, medicine, science, and more.
Whether you’re hosting a quiz event, preparing a session for students, or just looking for quality trivia to enjoy with friends, this PowerPoint deck is perfect for you.
📋 Quiz Format & Structure
Total Questions: ~50
Types: MCQs, one-liners, image-based, visual connects, lateral thinking
Rounds: Warm-up, Main Quiz, Visual Round, Connects (optional bonus)
Design: Simple, clear slides with answer explanations included
Tools Needed: Just a projector or screen – ready to use!
🧠 Who Is It For?
College quiz clubs
School or medical students
Teachers or faculty for classroom engagement
Event organizers needing quiz content
Quizzers preparing for competitions
Freelancers building quiz portfolios
💡 Why Use This Quiz?
Ready-made, high-quality content
Curated with lateral thinking and storytelling in mind
Covers both academic and pop culture topics
Designed by a quizzer with real event experience
Usable in inter-college fests, informal quizzes, or Sunday brain workouts
📚 About the Creators
This quiz has been created by Rana Mayank Pratap, an MBBS student and quizmaster at SMC Quiz Club, Silchar Medical College. The club aims to promote a culture of curiosity and smart thinking through weekly and monthly quiz events.
🔍 SEO Tags:
quiz, general knowledge quiz, trivia quiz, SlideShare quiz, college quiz, fun quiz, medical college quiz, India quiz, pop culture quiz, visual quiz, MCQ quiz, connect quiz, science quiz, current affairs quiz, SMC Quiz Club, Silchar Medical College
📣 Reuse & Credit
You’re free to use or adapt this quiz for your own events or sessions with credit to:
SMC Quiz Club – Silchar Medical College & Hospital
Curated by: Rana Mayank Pratap
2. 2
C++ Functions Types
• In programming, function refers to a segment that
groups code to perform a specific task.
• Depending on whether a function is predefined or
created by programmer; there are two types of function:
• Library Function (Built-in functions)
• User-defined Function(Programmer-defined)
C++
Programming,
Ali
Alsbou
3. 3
Built-in functions
• pre-defined functions which are usually grouped into
specialized libraries .
• For using a predefined C++ Standard Library function we
have to include in our program the header file in which
the function is defined.
• For Example:
<math.h> library which include some functions like
(sqrt, abs,…)
Programmer can use library function by invoking function
directly; they don't need to write it themselves.
C++
Programming,
Ali
Alsbou
4. 4
C++ Standard Library
• Mathematical calculations (…< math.h >)
• String manipulations (…<string.h >)
• Input/Output (….< iostream.h >)
• Error checking (…< exception.h >)
• Format output ( <iomanip.h> )
C++
Programming,
Ali
Alsbou
5. 5
Math Library Functions
Math Library Functions header file : math.h (C) or cmath (C++)
Function name Description
sin(x) Compute sine of x ( x in radians )
cos(x) Compute cosine of x ( x in radians )
tan (x) Compute tangent of x ( x in radians )
sqrt(x) Compute square root of x
pow(x , y) x raised to power y xy
ceil(x) rounds x to the smallest integer not less than x
floor(x) Returns the largest interger value smaller than or equal to
Value. (Rounds down)
fmod(x,y) Compute remainder of division as floating point number
abs(x) Compute absolute value of x return integer number
fabs(x) Compute absolute value of x return floating point number
C++
Programming,
Ali
Alsbou
6. Function Calling
6
• Programmer can use library function by
invoking(call)function directly
• Functions called by writing
functionName (argument);
// parameters , variables,
info
or
functionName(argument1, argument2, …);
• Function Arguments can be:
- constant sqrt(9);
- variable sqrt(x);//x is variable
- expression sqrt( x*9 + y) ;
sqrt( sqrt(x) ) ;
C++
Programming,
Ali
Alsbou
7. 7
Example(1)
How does it work?
Sqrt(x) : Compute square root of x
cout << sqrt( 9 );
− sqrt return value (3)
− So: cout << 3;
• if (sqrt( 16 )== 4 ) cout<< sqrt(16);
• value= sqrt( 16 )
8. 8
Example (2):
Using a functions within Code
#include <iostream>
#include <cmath> // <math.h>
int main(){
double number, squareRoot;
cout << "Enter a number: ";
cin >> number;
squareRoot = sqrt(number);
cout<<"Square root of "
<<number<<" = "<<squareRoot;
return 0;
}
9. 9
Example (3)
Write a C++ program to compute sin(90),tan(90) ,cos(60),cos(0),tan(0)
C++
Programming,
Ali
Alsbou
10. pow(x , y)
• pow(x , y): Compute x raised to power y and
return integer number only
cout<<"raises 4 to the 2 power is:"<<pow(4, 2);
• Example (4) :
− cout<<"pow(2,3)= "<< pow(2,3)<<endl;
− cout<<"2*pow(2,3)= "<< 2*pow(2,3)<<endl;
− cout<<"pow(2,pow(2,3))= "
<<pow(2,pow(2,3))<<endl;
10
C++
Programming,
Ali
Alsbou
13. floor(x) & ceil (x)
• floor Removes the fractional part of an integer. When
dealing with negative numbers, int rounds down.
• Example(7):
− floor ( 5 ) // is 5
− floor (4.6) // is 4
− floor (-4.6)// is -5
− floor (-4.1) // is -5
• ceil rounds x to the smallest integer not less than x .
When dealing with negative numbers, Removes the fractional
part of an integer.
• Example(8) :
− ceil( 5 ) // is 5
− ceil(4.6) // is 5
− ceil(-4.6)// is -4
− ceil(-4.1) // is -4
− If x=-4.499 then ceil(x+2) // -2
13
C++
Programming,
Ali
Alsbou
Returns the largest interger
value smaller than or equal
to Value. (Rounds down)
14. abs & fabs
• abs(x) : return integer number only
• fabs(x) : Compute absolute value of x
return floating point number
• Example(9) :
− cout<<" | 5.2 |= "<< fabs(5.2);
− cout<<" | -5 |= "<< fabs(-5);
− cout<<" |-5.3 |= "<< fabs(-5.3);
− cout<<" | 0 |= "<< fabs(0);
Example :
cout<<" | - 5.3 |= "<< abs(- 5.3 );
14
C++
Programming,
Ali
Alsbou
16. Exercise(1)
• What the last value of x on the following:
1. x=floor(ceil( 20.3 )-2); // x= 19
• ceil(20.3) rounds 20.3 to the smallest integer not less than
20.3 = 21
• floor(21) rounds 21 to the largest integer not greater than
21 >>>> 21
• 21- 2 = 19
• floor(19) = 19
2. x= pow(sqrt(4),floor(fabs(3.2))); //x=8
16
C++
Programming,
Ali
Alsbou
17. Random number generation
stdlib.h library
• rand function use to generate an integer
value between 0 and RAND-MAX (~32,767)
• rand function defined in<stdlib.h> library
17
C++
Programming,
Ali
Alsbou
18. Generating a number statement:
open-range and specific range
• rand() // [0, RAND-MAX] open-
range
• Generating a number in a specific
range : Scaling:
− rand()%(max + 1) // [0, max]
− To generate numbers in the range [min,
max]:
rand()% (max - min + 1) + min
18
C++
Programming,
Ali
Alsbou
19. 19
Examples (11):
1. x=rand(); //x has any number 0..RAND-MAX
2. generate 10 random numbers(open-range)
int x;
for( int i=0; i<=10; i++)
{
x=rand();
cout<<x<< " ";
}
20. Examples (12):
Statement
range
•num=rand()%8; // [0..7]
•num=rand()%55; // [0..54]
•num=rand()%8+2; // [2,9]
•num=rand()%17-22; // [-22,-
6]
•num=rand()%19-3; // [-3,15]
20
C++
Programming,
Ali
Alsbou
21. 21
How to ?
• num=rand()%8+2; //
[2,9]
rand()% (max - min + 1) + min
(max - min + 1) + min=8
(max - 2 + 1) + 2=8
(max - 3) + 2=8
max =8 + 3 – 2
max =9
rand()% (9 - 2 + 1) + 2
22. Example(13)
//generate 10 integers between 0..49
int x;
for( int i=0; i<10; i++)
{
x=rand()%50;
cout<<x<< " ";
}
22
C++
Programming,
Ali
Alsbou
Note: the rand( ) function will generate
the same set of random numbers each time you
run the program
23. Example(14)
23
C++
Programming,
Ali
Alsbou
//generate 10 integers between 5…15
int x;
for (int i=1; i<=10; i++){
x= rand() % 11 + 5;
cout<<x<<" ";
}
//generate 100 number as simulation of
rolling a dice
int x;
for (int i=1; i<=100; i++){
x= rand % 6 + 1;
cout<<x<<" ";
}
24. rand function:
Generate from specific range with specific elements
24
C++
Programming,
Ali
Alsbou
• [ 1, 2, 3, 4, 5]
rand() % 5 + 1
• [ 2, 4, 6, 8, 10]
(rand() % 5 + 1) * 2
• [3, 5, 7, 9, 11 ]
(rand() % 5 + 1) * 2 + 1
• [6, 10, 14, 18, 22]
((rand() % 5 + 1) * 2 + 1) * 2
25. Example (15) : rand()
#include <iostream.h>
#include <stdlib.h>
int main()
{
for(int i = 1; i <= 10; i++)
cout << rand() << endl;
return 0;
}
38457
733887
7384
94877
243
3994452
374008
23146
11833432
237844
First
Execution
Output
38457
733887
7384
94877
243
3994452
374008
23146
11833432
237844
Second
Execution
Output
Note: the rand( ) function will generate the same
set of random numbers each time you run the program
C++
Programming,
Ali
Alsbou
26. srand
• The rand( ) function will generate the
same set of random numbers each time you
run the program
• To force NEW set of random numbers with
each new run use the randomizing process
by using function srand(integer);
• srand(seed);
26
C++
Programming,
Ali
Alsbou
27. srand – con’t.
A popular method for seeding is to use the
system clock.
srand(time(NULL)); //“Randomizes" the
seed
•time(NULL):Function in <time.h> library
returns the time at which the program was
executed
27
C++
Programming,
Ali
Alsbou
28. Example (16): srand()
generates a new random set each
time:
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
int main()
{
srand(time(NULL));
for(int i = 1; i <= 10; i++)
cout << rand() << endl;
return 0;
}
464
53735
342
23
6578
889
93723
7165
7422457
78614
First
Execution
Output
6877
245768
215
57618
78511
79738
3461
175117
35
257868
Second
Execution
Output
C++
Programming,
Ali
Alsbou
30. 30
Header File: stdlib.h (C) or cstdlib (C++)
exit() function.
#include <stdlib.h>
#include <iostream.h>
main()
{
cout<<"Program will exit";
exit(1);//Returns 1 to the operating system
cout<<"Never executed";
}
C++
Programming,
Ali
Alsbou
31. 31
Character Functions
Character handling functions
C++
Programming,
Ali
Alsbou
#include <cctype> (or older <ctype.h>)
• Because these are the original C
functions, bool isn't used. Instead,
zero is false and non-zero is true.
• types of the parameters are c=char/int.
function Description
isalnum(c) true if c is a letter or digit.
isalpha(c) true if c is a letter.
isdigit(c) true if c is a digit.
islower(c) true if c is a lowercase letter.
isupper(c) true if c is an uppercase letter.
32. 32
most common functions to with
single characters.
isspace(c) true if c is whitespace character (space, tab,
vertical tab, carriage return, or newline).
tolower(c) returns lowercase version of c if there is one,
otherwise it returns the character unchanged.
toupper(c) returns uppercase version of c if there is one,
otherwise it returns the character unchanged.
33. 33
Example (17)
#include <iostream.h>
#include <ctype.h>
int main( ){
char c;
cin>> c;
if(isalnum(c))
cout<<c<<" is an alphanumeric character.n";
else
cout<<c<<" is not an alphanumeric
character.";
}
34. 34
Formatting Output (setw)
iomanip library
• setw() is library function in C++ and is
declared inside #include<iomanip>
• Setw(n):Sets the number of characters
(field width n) to be used on output
operations for the next insertion
operation.
C++
Programming,
Ali
Alsbou
38. String Function :
The C-style character string
<cstring.h> or <string.h> are a header file
that contains many functions for
manipulating:
• Copy functions :strcpy,strncpy
• Concatenate strings functions :strcat ,
strncat
• Comparison functions : strcmp,strncmp
• Other functions : strlen
38
C++
Programming,
Ali
Alsbou
39. 39
strlen : String Length Check Function
Syntax : strlen(str)
– str :array of characters
– int strlen(char str);
• returns the length of String (integer
value) without null character (read
string until 0)
• If the null terminator is the first
character (empty string), it returns 0
C++
Programming,
Ali
Alsbou
41. String Copy Function
strcpy & strncpy
• Syntax : strcpy(string1, string2);
− string1:destination.
− string2:source
• Copy the content of the 2nd
string into the
1st
string, including the terminating null
character (and stopping at that point).
return string1
− replace content of string1 with string2
start from first element character by
character
− if number of string2 elements plus 1(‘n’)
less than string1 elements , it keep the
remaining elements in string1
41
C++
Programming,
Ali
Alsbou
42. 42
Example (21)
char str1[]=“information"; allocate 12 in memory
str1
strcpy(str1, "AB");
i n f o r m a t i o n 0
A B 0 o r m a t i o n 0
str1
C++
Programming,
Ali
Alsbou
cout<<str1; AB
44. strncpy
Syntax : strncpy(string1, string2,n);
Description : copies 'n' bytes from str2 to str1
− if n less than or equal length source string2;
copy n character of a string2 without null
character.
− Else copy part of a string2 with null
character
44
C++
Programming,
Ali
Alsbou
45. Example (23)
45
char str1[]="information"; allocate 12 in memory
str1 i n f o r m a t i o n 0
N e w o r m a t i o n 0
str1
C++
Programming,
Ali
Alsbou
cout<<str1; Print Newormation since Characters printed
until null found
strncpy(str1, "New",3);
46. Example (24)
46
char str1[]="information"; allocate 12 in memory
str1 i n f o r m a t i o n 0
N e w 0 0 m a t i o n 0
str1
C++
Programming,
Ali
Alsbou
cout<<str1; Print New since Characters printed until null found
strncpy(str1, "New",5); // 5 > strlen("New")
for (i=0; i<11;i++)
cout << str1[i];
Print New mation since it part of array
49. 49
strcat :String Concatenation
Syntax : strcat(string1, string2);
• Concatenation is taking two strings and
then make them become one string
• This function takes the second string and
appends it to the first string,
overwriting the appends character at the
end of the first string with the first
character of the second string
• The last character copied onto the end of
the first string is the null character of
the second string.
C++
Programming,
Ali
Alsbou
50. Example(27) :
String Concatenation
H e l l o J i m 0
string1
char string1[10] = "Hello";
char string2[10] = "Jim";
strcat(string1,string2);
H e l l o 0
J i m 0
string1
string2
C++
Programming,
Ali
Alsbou
52. String Comparison : strcmp
Syntax : strcmp (string1, string2);
takes two strings and returns an integer value:
− A negative integer if string1 is less than
string2.
− Zero if string1 equals str2.
− A positive integer if string1 is greater than
string2.
52
C++
Programming,
Ali
Alsbou
If Result
string1< string2 < 0
string1> string2 > 0
string1== string2 == 0
53. String Comparison
There are two rules for less than/greater than strings:
every character (symbol) is actually a number, as defined by the
ASCII code.
◦ Compare one character in str1 with one character in str2
which have the same index(n) if:
◦ two characters are match move to next pairs of character with
next index also.
◦ On first non-matching characters . str1 is less than str2 if
str1[n] < str2[n] else str1 is greater than str2.
◦ If str1 is shorter in length than str2 and all of the characters of
str1 match the corresponding characters of str2, str1 is less
than str2.
C++
Programming,
Ali
Alsbou
With Letter order (a..z, or A.. Z)
Value is increase
A value is 65
B value is 66
a value is 97
54. 54
Example(29)
str1 str2
return
value
reason
"AAAA" "ABCD" <0 ‘A’ <‘B’
"B123" "A089" >0 ‘B’ > ‘A’
"127" "409" <0 ‘1’ < ‘4’
"abc888" "abc888" =0 equal string
"abc" "abcde" <0 str1 is a sub string
of str2
"3" "12345" >0 ‘3’ > ‘1’
C++
Programming,
Ali
Alsbou
56. 56
Exercises
• So what would be the result of the
following comparison function calls?
− strcmp("hello", "jackson");
− strcmp("red balloon", "red car");
− strcmp("blue", "blue");
− strcmp("aardvark", "aardvarks");
Note :
− ‘0’ value is 0
− ‘ ‘ (space) value is 32
C++
Programming,
Ali
Alsbou
Some ASCII code.
57. 57
Example (30)
#include <iostream.h>
#include <string.h>
main()
{
char x[6]="ABCZ";
char y[6]="ABCZ ";
if((strcmp(x,y)) < 0)
cout<<"The result is :x is less than y";
else if((strcmp(x,y)) > 0)
cout<<"The result is :x is greater than y";
else
cout<<"The result is :x equal to y";
}
58. 58
strncmp
Same as strcmp except that at most limit
characters are compared
Syntax : strncmp (string1, string2,n);
C++
Programming,
Ali
Alsbou
60. Some Common Errors
It is illegal to assign a value to a
string variable (except at declaration).
char A_string[10];
A_string="Hello";// illegal assignment
Should use instead
strcpy (A_string, "Hello");
C++
Programming,
Ali
Alsbou
61. Some Common Errors
The operator == doesn't test two strings for
equality.
e.g.:
if (string1 == string2)//wrong illegal comparison
cout << "Yes!";
Should use instead
if (strcmp(string1,string2)==0)
cout << "Yes they are same!";
//note that strcmp returns 0 (false) if the two
strings are the same.
C++
Programming,
Ali
Alsbou
62. Concatenation
• Plus “+” is used for string concatenation: s3=s1 + ”to” + s2;
− at least one operand has to be string variable!
• Compound concatenation allowed: s1 += ”duction”;
• Characters can be concatenated with strings:
s2= s1 + ’o’;
s2+=’o’;
• No other types can be assigned to strings or concatenated with strings:
s2= 42.54; // error
s2=”Catch” + 22; // error
63. • Comparison operators (>, <, >=, <=, ==, !=) are
applicable to strings
string s1=”accept”, s2=”access”,
s3=”acceptance”;
s1 is less than s2 and s1 is less than s3
• Order of symbols is determined by the symbol table
(ASCII)
− letters in the alphabet are in the increasing order
− longer word (with the same characters) is greater than
shorter word
− relying on other ASCII properties (e.g. capital letters
are less than small letters) is bad style
Comparing Strings
64. • Number of standard functions are defined for strings. Usual
syntax:
string_name.function_name(arguments)
• Useful functions return string parameters:
− size() - current string size (number of characters currently
stored in string
− length()- same as size()
− max_size() - maximum number of characters in string
allowed on this computer
− empty() - true if string is empty
• Example:
string s=”Hello”;
cout << s.size(); // outputs 5
String Functions
String Characteristics
65. • Similar to arrays a character in a string can be accessed
and assigned to using its index (start from 0)
cout << str[3];
• Using Substrings function
Accessing Elements of Strings
66. • substr - function that returns a substring of a string:
substr(start, numb), where
start - index of the first character,
numb - number of characters(bytes)
• Example:
string s=”Hello”;
cout << s.substr(3,2); // outputs ”lo”
----------------------
string s="123456789"; // size is 5
cout << s.substr(3,2); // outputs ”45”
Substrings - function
67. • find family of functions return position of substring found, if
not found return global constant string::npos defined in
string header
− find(substring) - returns the position of the first
character of substring in the string
− rfind(substring) - same as find, search in reverse
− find_first_of(substring) - finds first occurrence of
any character of substring in the string
− find_last_of(substring) - finds last occurrence of
any character of substr in the string
• All functions work with individual characters as well:
cout << s.find(“l”);
Searching - functions
68. • insert(start, substring)- inserts
substring starting from position start
string s=”place”;
cout << s.insert(1, ”a”); // s=”palace”
• Variant insert(start, number, character)
– inserts number of character starting from
position start
string s=”place”;
cout << s.insert(4, 2, ’X’);//s= ”placXXe”
− note: ‘x’ is a character not a string
Inserting
69. • replace (start, number, substring)-
replaces number of characters starting from start
with substring
− the number of characters replaced need not be the
same
• Example
string s=”Hello”;
s.replace(1,4, ”i, there”); //s is ”Hi, there”
Replacing
70. • append(string2)- appends string2 to the end of the
string
string s=”Hello”;
cout << s.append(”, World!”);
cout << s; // outputs ”Hello, World!”
• erase(start, number)- removes number of
characters starting from start
string s=”Hello”;
s.erase(1,2);
cout << s; // outputs ”Hlo”
• clear()- removes all characters
s.clear(); // s becomes empty
Appending, Erasing
71. • Strings (unlike arrays) can be returned:
− string myfunc(int, int);
• Note: passing strings by value and returning
strings is less efficient than passing them by
reference
• However, efficiency should in most cases be
sacrificed for clarity
Returning Strings
72. C-string Problems
• C-strings problems stem from the underlying array
• With C-style strings the programmer must be careful not
to access the arrays out of bounds
• Consider string concatenation, combining two strings to
form a single string
− Is there room in the destination array for all the characters and
the null?
• The C++ string class manages the storage automatically
and does not have these problems
Editor's Notes
#2: External functions (e.g., abs, ceil, rand, sqrt, etc.)are usually grouped into specialized libraries (e.g., iostream, stdlib, math, etc.)
#3: The Standard C++ Library contains a large collection of predefined functions which may be
called and used by programmers.
For using a predefined C++ Standard Library function we have to include in our program
the header file in which the function is defined.
#13: floor :Explanation: Returns the largest interger value smaller than or equal to Value. (Rounds down)
#34: This manipulator is declared in header <iomanip>.
#36: This manipulator is declared in header <iomanip>.
#37: #include<iomanip.h>
int main()
{
int i;
for (i=0;i<3;i++)
cout <<"ABC"<<setw(5);
cout<<"\n";
for (i=0;i<3;i++)
cout <<"ABC"<<setw(2);
cout<<"\n";
for (i=0;i<3;i++)
cout <<setw(4)<<"ABC";
cout<<"\n";
for (i=0;i<3;i++)
cout <<setw(4)<<"ABC"<<setw(3)<<"EF";
return 0;
}
#57: #include <iostream.h>
#include <string.h>
main()
{
char x[6]="ABCZ ";
char y[6]="ABCZ ";
if((strcmp(x,y)) < 0)
cout<<"The result is :x is less than y";
else if((strcmp(x,y)) > 0)
cout<<"The result is :x is greater than y";
else
cout<<"The result is :x equal to y";
}
#59: #include <iostream.h>
#include <string.h>
main()
{
char x[6]="ABCZ ";
char y[6]="ABCD ";
char z[6]="ABB" ;
if((strncmp(x,y,4)) < 0)
cout<<"1.The result is :x is less than y\n";
else
cout<<"2.The result is :x is greater than y\n";
if((strncmp(x,y,3)) == 0)
cout<<"3. The result is :x equal to y\n";
if((strncmp(x,z,3)) > 0)
cout<<"4.The result is :x greater than z";
}