SlideShare a Scribd company logo
1 of 2
Exercises: 
1) General questions: 
a) How can we pass an array by value? 
b) How can we pass an int by reference? 
c) How can we retrieve the length of an array? 
d) How can we append new items to an array? 
2) Get acquainted with the usage of arrays. What happens if you create an array of size 
ten and: 
a) access the element at index 10? 
b) access the element at index -1? 
Document the results with screenshots if required. 
3) Create a function that accepts at least two array arguments. The function should copy 
the content of one array into the other array. 
a) Write a test program to test your function. 
b) Which error cases do you need to handle in this function? 
4) What happens if you dereference a 0-pointer? Document the result with screenshots if 
required. 
5) Re-implement the program that calculates to sum of squares with an array of five 
items. 
6) Learn how to get and process command line arguments of a C++ program. Also learn 
how you can pass these arguments from within your IDE in order to debug the 
program. You need this information in the next exercise. 
7) In another program the user should input a string via command line arguments. The 
program checks, whether the passed string is a palindrome. A palindrome is a 
"symmetric" word, i.e. such a word that can be read from left to right and from right to 
left having the same wording, e.g. "otto", "anna", "lagerregal". After the check following 
output should be generated: "anna is a palindrome". The case of the word's letters 
should be regarded, so "Otto" is no palindrome. The check for a word to be a 
palindrome should be implemented in a single function with following signature: 
bool IsPalindrome(const char* word); 
A function, which tests an argument against a criterion is sometimes called predicate. 
8) Develop a function that awaits a source string and a substring. The result of this 
function is the count of occurrences of the substring in the source string. This function 
will have following signature: 
int CountSubString(const char* source, const char* subString); 
The functionality of the function should be proved with a test program. 
9) Write a void-function that returns an int-value via a parameter. 
Remarks: 
• Everything that was left unspecified can be solved as you prefer. 
• The usage of goto, C++11 extensions, as well as #pragmas is not allowed. The usage 
of global variables is not allowed. You mustn't use the STL (e.g. std::string), but 
std::cout, std::cin and belonging to manipulators can be used. You mustn't use new 
and delete! You are not allowed to use C++ references instead of pointers. 
• Avoid magic numbers and use constants where possible. 
• The results of the programming exercises need to be runnable applications! All
programs have to be implemented as console programs. 
• The programs need to be robust, i.e. they should cope with erroneous input from the 
user. 
• You should be able to describe your programs after implementation. Comments are 
mandatory. 
• In documentations as well as in comments, strings or user interfaces make correct use 
of language (spelling and grammar)! 
• Don't send binary files (e.g. the contents of debug/release folders) with your solutions! 
Do only send source and project files. 
• Don't panic: In programming multiple solutions are possible. 
• If you have problems use the Visual Studio help (F1) or the Xcode help, books and the 
internet primarily. 
• Of course you can also ask colleagues; but it is of course always better, if you find a 
solution yourself.

More Related Content

What's hot

computer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressionscomputer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressions
ecomputernotes
 
computer notes - Conversion from infix to postfix
computer notes - Conversion from infix to postfixcomputer notes - Conversion from infix to postfix
computer notes - Conversion from infix to postfix
ecomputernotes
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
Kumar
 

What's hot (18)

Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
Unit iv
Unit ivUnit iv
Unit iv
 
computer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressionscomputer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressions
 
Revision test of unit
Revision test of unitRevision test of unit
Revision test of unit
 
The c++coreguidelinesforsavercode
The c++coreguidelinesforsavercodeThe c++coreguidelinesforsavercode
The c++coreguidelinesforsavercode
 
computer notes - Conversion from infix to postfix
computer notes - Conversion from infix to postfixcomputer notes - Conversion from infix to postfix
computer notes - Conversion from infix to postfix
 
VivaMP, system of detecting errors in the code of parallel C++ programs using...
VivaMP, system of detecting errors in the code of parallel C++ programs using...VivaMP, system of detecting errors in the code of parallel C++ programs using...
VivaMP, system of detecting errors in the code of parallel C++ programs using...
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 
Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]
 
005
005005
005
 
Pointers c5
Pointers c5Pointers c5
Pointers c5
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
OOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NETOOPS With CSharp - Jinal Desai .NET
OOPS With CSharp - Jinal Desai .NET
 
Polyspace CETIC presentation
Polyspace CETIC presentationPolyspace CETIC presentation
Polyspace CETIC presentation
 
First program of C ( Complete Explanation )
First program of C ( Complete Explanation )First program of C ( Complete Explanation )
First program of C ( Complete Explanation )
 
[C++ korea] effective modern c++ study item 4 - 6 신촌
[C++ korea] effective modern c++ study   item 4 - 6 신촌[C++ korea] effective modern c++ study   item 4 - 6 신촌
[C++ korea] effective modern c++ study item 4 - 6 신촌
 
Exceptions
ExceptionsExceptions
Exceptions
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
 

Similar to (4) cpp automatic arrays_pointers_c-strings_exercises

Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
josephineboon366
 

Similar to (4) cpp automatic arrays_pointers_c-strings_exercises (20)

(6) cpp numeric representation_exercises
(6) cpp numeric representation_exercises(6) cpp numeric representation_exercises
(6) cpp numeric representation_exercises
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
 
(3) cpp procedural programming_exercises
(3) cpp procedural programming_exercises(3) cpp procedural programming_exercises
(3) cpp procedural programming_exercises
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
 
1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt
 
Boo Manifesto
Boo ManifestoBoo Manifesto
Boo Manifesto
 
I x scripting
I x scriptingI x scripting
I x scripting
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
علم البيانات - Data Sience
علم البيانات - Data Sience علم البيانات - Data Sience
علم البيانات - Data Sience
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
 

More from Nico Ludwig

New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 

More from Nico Ludwig (20)

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_v
 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_iv
 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iii
 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_ii
 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_i
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iii
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_i
 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_v
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 

Recently uploaded

Recently uploaded (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

(4) cpp automatic arrays_pointers_c-strings_exercises

  • 1. Exercises: 1) General questions: a) How can we pass an array by value? b) How can we pass an int by reference? c) How can we retrieve the length of an array? d) How can we append new items to an array? 2) Get acquainted with the usage of arrays. What happens if you create an array of size ten and: a) access the element at index 10? b) access the element at index -1? Document the results with screenshots if required. 3) Create a function that accepts at least two array arguments. The function should copy the content of one array into the other array. a) Write a test program to test your function. b) Which error cases do you need to handle in this function? 4) What happens if you dereference a 0-pointer? Document the result with screenshots if required. 5) Re-implement the program that calculates to sum of squares with an array of five items. 6) Learn how to get and process command line arguments of a C++ program. Also learn how you can pass these arguments from within your IDE in order to debug the program. You need this information in the next exercise. 7) In another program the user should input a string via command line arguments. The program checks, whether the passed string is a palindrome. A palindrome is a "symmetric" word, i.e. such a word that can be read from left to right and from right to left having the same wording, e.g. "otto", "anna", "lagerregal". After the check following output should be generated: "anna is a palindrome". The case of the word's letters should be regarded, so "Otto" is no palindrome. The check for a word to be a palindrome should be implemented in a single function with following signature: bool IsPalindrome(const char* word); A function, which tests an argument against a criterion is sometimes called predicate. 8) Develop a function that awaits a source string and a substring. The result of this function is the count of occurrences of the substring in the source string. This function will have following signature: int CountSubString(const char* source, const char* subString); The functionality of the function should be proved with a test program. 9) Write a void-function that returns an int-value via a parameter. Remarks: • Everything that was left unspecified can be solved as you prefer. • The usage of goto, C++11 extensions, as well as #pragmas is not allowed. The usage of global variables is not allowed. You mustn't use the STL (e.g. std::string), but std::cout, std::cin and belonging to manipulators can be used. You mustn't use new and delete! You are not allowed to use C++ references instead of pointers. • Avoid magic numbers and use constants where possible. • The results of the programming exercises need to be runnable applications! All
  • 2. programs have to be implemented as console programs. • The programs need to be robust, i.e. they should cope with erroneous input from the user. • You should be able to describe your programs after implementation. Comments are mandatory. • In documentations as well as in comments, strings or user interfaces make correct use of language (spelling and grammar)! • Don't send binary files (e.g. the contents of debug/release folders) with your solutions! Do only send source and project files. • Don't panic: In programming multiple solutions are possible. • If you have problems use the Visual Studio help (F1) or the Xcode help, books and the internet primarily. • Of course you can also ask colleagues; but it is of course always better, if you find a solution yourself.