I am Arnold H. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
Homework Assignment – Array Technical Document
Write a technical document that describes the structure and use of arrays. The document should
be 3 to 5 pages and include an Introduction section, giving a brief synopsis of the document and
arrays, a Body section, describing arrays and giving an annotated example of their use as a
programming construct, and a conclusion to revisit important information about arrays described
in the Body of the document. Some suggested material to include:
Declaring arrays of various types
Array pointers
Printing and processing arrays
Sorting and searching arrays
Multidimensional arrays
Indexing arrays of various dimension
Array representation in memory by data type
Passing arrays as arguments
If you find any useful images on the Internet, you can use them as long as you cite the source in
end notes.
Solution
Array is a collection of variables of the same type that are referenced by a common name.
Specific elements or variables in the array are accessed by means of index into the array.
If taking about C, In C all arrays consist of contiguous memory locations. The lowest address
corresponds to the first element in the array while the largest address corresponds to the last
element in the array.
C supports both single and multi-dimensional arrays.
1) Single Dimension Arrays:-
Syntax:- type var_name[size];
where type is the type of each element in the array, var_name is any valid identifier, and size is
the number of elements in the array which has to be a constant value.
*Array always use zero as index to first element.
The valid indices for array above are 0 .. 4, i.e. 0 .. number of elements - 1
For Example :- To load an array with values 0 .. 99
int x[100] ;
int i ;
for ( i = 0; i < 100; i++ )
x[i] = i ;
To determine to size of an array at run time the sizeof operator is used. This returns the size in
bytes of its argument. The name of the array is given as the operand
size_of_array = sizeof ( array_name ) ;
2) Initialisg array:-
Arrays can be initialised at time of declaration in the following manner.
type array[ size ] = { value list };
For Example :-
int i[5] = {1, 2, 3, 4, 5 } ;
i[0] = 1, i[1] = 2, etc.
The size specification in the declaration may be omitted which causes the compiler to count the
number of elements in the value list and allocate appropriate storage.
For Example :- int i[ ] = { 1, 2, 3, 4, 5 } ;
3) Multidimensional array:-
Multidimensional arrays of any dimension are possible in C but in practice only two or three
dimensional arrays are workable. The most common multidimensional array is a two
dimensional array for example the computer display, board games, a mathematical matrix etc.
Syntax :type name [ rows ] [ columns ] ;
For Example :- 2D array of dimension 2 X 3.
int d[ 2 ] [ 3 ] ;
A two dimensional array is actually an array of arrays, in the above case an array of two integer
arrays (the rows) each with three elements, and is stored row-wise in memory.
For Example :- Program to fill .
The objective of the Level 5 Diploma in Information Technology is to provide learners with an excellent foundation for a career in a range of organisations. It designed to ensure that each learner is ‘business ready’: a confident, independent thinker with a detailed knowledge of Information Technology, and equipped with the skills to adapt rapidly to change.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
Homework Assignment – Array Technical Document
Write a technical document that describes the structure and use of arrays. The document should
be 3 to 5 pages and include an Introduction section, giving a brief synopsis of the document and
arrays, a Body section, describing arrays and giving an annotated example of their use as a
programming construct, and a conclusion to revisit important information about arrays described
in the Body of the document. Some suggested material to include:
Declaring arrays of various types
Array pointers
Printing and processing arrays
Sorting and searching arrays
Multidimensional arrays
Indexing arrays of various dimension
Array representation in memory by data type
Passing arrays as arguments
If you find any useful images on the Internet, you can use them as long as you cite the source in
end notes.
Solution
Array is a collection of variables of the same type that are referenced by a common name.
Specific elements or variables in the array are accessed by means of index into the array.
If taking about C, In C all arrays consist of contiguous memory locations. The lowest address
corresponds to the first element in the array while the largest address corresponds to the last
element in the array.
C supports both single and multi-dimensional arrays.
1) Single Dimension Arrays:-
Syntax:- type var_name[size];
where type is the type of each element in the array, var_name is any valid identifier, and size is
the number of elements in the array which has to be a constant value.
*Array always use zero as index to first element.
The valid indices for array above are 0 .. 4, i.e. 0 .. number of elements - 1
For Example :- To load an array with values 0 .. 99
int x[100] ;
int i ;
for ( i = 0; i < 100; i++ )
x[i] = i ;
To determine to size of an array at run time the sizeof operator is used. This returns the size in
bytes of its argument. The name of the array is given as the operand
size_of_array = sizeof ( array_name ) ;
2) Initialisg array:-
Arrays can be initialised at time of declaration in the following manner.
type array[ size ] = { value list };
For Example :-
int i[5] = {1, 2, 3, 4, 5 } ;
i[0] = 1, i[1] = 2, etc.
The size specification in the declaration may be omitted which causes the compiler to count the
number of elements in the value list and allocate appropriate storage.
For Example :- int i[ ] = { 1, 2, 3, 4, 5 } ;
3) Multidimensional array:-
Multidimensional arrays of any dimension are possible in C but in practice only two or three
dimensional arrays are workable. The most common multidimensional array is a two
dimensional array for example the computer display, board games, a mathematical matrix etc.
Syntax :type name [ rows ] [ columns ] ;
For Example :- 2D array of dimension 2 X 3.
int d[ 2 ] [ 3 ] ;
A two dimensional array is actually an array of arrays, in the above case an array of two integer
arrays (the rows) each with three elements, and is stored row-wise in memory.
For Example :- Program to fill .
The objective of the Level 5 Diploma in Information Technology is to provide learners with an excellent foundation for a career in a range of organisations. It designed to ensure that each learner is ‘business ready’: a confident, independent thinker with a detailed knowledge of Information Technology, and equipped with the skills to adapt rapidly to change.
ObjectivesMore practice with recursion.Practice writing some tem.docxvannagoforth
Objectives
More practice with recursion.
Practice writing some template functions.
Use stack ADT to implement given algorithms.
Look at some common applications of stacks.Description
In this assignment, you will be using the Stack abstract data type we developed this week and discussed in our weeks lectures, to implement 4 functions that use a stack data type to accomplish their algorithms. The functions range from relatively simple, straight forward use of a stack, to a bit more complex. But in all 4 cases, you should only need to use the abstract stack interface functions push(), pop(), top(), and isEmpty() in order to successfully use our Stack type for this assignment and the function you are asked to write.
For this assignment you need to perform the following tasks.
1. In the rst task, we will write a function that will check if a string of parenthesis is matching. Strings will be given to the function of the format "(()((())))", using only opening "(" and closing ")". Your function should be named doParenthesisMatch(). It takes a single string as input, and it returns a boolean result of true if the parenthesis match, and false otherwise.
The algorithm to check for matching parenthesis using a stack is fairly simple. A pseudo-code description migth be
for each charcter c in expression do
if c is an open paren ’(’ push it on stack
if c is a close paren ’)’:
do
if stack is empty
answer is false, because we can’t match the current ’)’
else pop stack, because we just matched an open ’(’ with a close ’)’
done
done
Your function will be given a C++ string class as input. It is relatively simple to parse each character of a C++ string. Here is an example for loop to do this:
s = "(())";
for (size_t index = 0; index < s.length(); index++)
{ char c = s[index];
// handle char c of the string expression s here }
2. In the next task, we will also write a function that decodes a string expression. Given a sequence consisting of ’I’ and ’D’ characters, where ’I’ denotes increasing and ’D’ denotes decreasing, decode the given sequence to construct a "minimum number" without repeated digits.
An example of some inputs and outputs will make it clear what is meant by a "minimal number".
sequence
output
IIII
->
12345
DDDD
->
54321
ID
->
132
IDIDII
->
1325467
IIDDIDID
->
125437698
If you are given 4 characters in the input sequence, the result will be a number with 5 characters, and further only the digits ’12345’ would be in the "minimal number" output. Each ’I’ and ’D’ in the input denotes that the next digit in the output should go up (increase) or go down (decrease) respectively. As you can see for the input sequence "IDI" you have to accommodate the sequence, thus the output goes from 1 to 3 for the initial increase, becase in order to then decrease, and also only have the digits ’123’, we need 3 for the second digit so the third can decrease to 2.
Take a moment to think how you might write an algorithm to solve this problem? It may be di cult to thi ...
Functions: Function Definition, prototyping, types of functions, passing arguments to functions, Nested Functions, Recursive functions.
Strings: Declaring and Initializing strings, Operations on strings, Arrays of strings, passing strings to functions. Storage Classes: Automatic, External, Static and Register Variables.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Visual programming (VP) refers to a method of programming that uses a graphical interface to create and modify code, rather than typing out code manually. Unlike traditional text-based programming, visual programming uses visual elements to represent code. Some graphical elements you can use when creating programs with VP include:
Struggling with your C++ homework? Don't let complex programming concepts and challenging assignments hold you back. We're here to provide you with the ultimate solution - expert C++ homework help that guarantees your success!
CPP Homework Help is quality-oriented and has invested heavily in quality control. We have put together the best team of CPP professionals combining talent, creativity, and experience. Our experts can handle every CPP homework and ensure the student secures high grades, within their submission deadline. Every homework is plagiarism free and a turn-it-in report is issued at the time of delivery.
Reach out to our team via: -
Website: https://www.cpphomeworkhelp.com/
Email: support@cpphomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
ObjectivesMore practice with recursion.Practice writing some tem.docxvannagoforth
Objectives
More practice with recursion.
Practice writing some template functions.
Use stack ADT to implement given algorithms.
Look at some common applications of stacks.Description
In this assignment, you will be using the Stack abstract data type we developed this week and discussed in our weeks lectures, to implement 4 functions that use a stack data type to accomplish their algorithms. The functions range from relatively simple, straight forward use of a stack, to a bit more complex. But in all 4 cases, you should only need to use the abstract stack interface functions push(), pop(), top(), and isEmpty() in order to successfully use our Stack type for this assignment and the function you are asked to write.
For this assignment you need to perform the following tasks.
1. In the rst task, we will write a function that will check if a string of parenthesis is matching. Strings will be given to the function of the format "(()((())))", using only opening "(" and closing ")". Your function should be named doParenthesisMatch(). It takes a single string as input, and it returns a boolean result of true if the parenthesis match, and false otherwise.
The algorithm to check for matching parenthesis using a stack is fairly simple. A pseudo-code description migth be
for each charcter c in expression do
if c is an open paren ’(’ push it on stack
if c is a close paren ’)’:
do
if stack is empty
answer is false, because we can’t match the current ’)’
else pop stack, because we just matched an open ’(’ with a close ’)’
done
done
Your function will be given a C++ string class as input. It is relatively simple to parse each character of a C++ string. Here is an example for loop to do this:
s = "(())";
for (size_t index = 0; index < s.length(); index++)
{ char c = s[index];
// handle char c of the string expression s here }
2. In the next task, we will also write a function that decodes a string expression. Given a sequence consisting of ’I’ and ’D’ characters, where ’I’ denotes increasing and ’D’ denotes decreasing, decode the given sequence to construct a "minimum number" without repeated digits.
An example of some inputs and outputs will make it clear what is meant by a "minimal number".
sequence
output
IIII
->
12345
DDDD
->
54321
ID
->
132
IDIDII
->
1325467
IIDDIDID
->
125437698
If you are given 4 characters in the input sequence, the result will be a number with 5 characters, and further only the digits ’12345’ would be in the "minimal number" output. Each ’I’ and ’D’ in the input denotes that the next digit in the output should go up (increase) or go down (decrease) respectively. As you can see for the input sequence "IDI" you have to accommodate the sequence, thus the output goes from 1 to 3 for the initial increase, becase in order to then decrease, and also only have the digits ’123’, we need 3 for the second digit so the third can decrease to 2.
Take a moment to think how you might write an algorithm to solve this problem? It may be di cult to thi ...
Functions: Function Definition, prototyping, types of functions, passing arguments to functions, Nested Functions, Recursive functions.
Strings: Declaring and Initializing strings, Operations on strings, Arrays of strings, passing strings to functions. Storage Classes: Automatic, External, Static and Register Variables.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Visual programming (VP) refers to a method of programming that uses a graphical interface to create and modify code, rather than typing out code manually. Unlike traditional text-based programming, visual programming uses visual elements to represent code. Some graphical elements you can use when creating programs with VP include:
Struggling with your C++ homework? Don't let complex programming concepts and challenging assignments hold you back. We're here to provide you with the ultimate solution - expert C++ homework help that guarantees your success!
CPP Homework Help is quality-oriented and has invested heavily in quality control. We have put together the best team of CPP professionals combining talent, creativity, and experience. Our experts can handle every CPP homework and ensure the student secures high grades, within their submission deadline. Every homework is plagiarism free and a turn-it-in report is issued at the time of delivery.
Reach out to our team via: -
Website: https://www.cpphomeworkhelp.com/
Email: support@cpphomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
Get help with C++ homework. Now you Don't have to look the other way. here we help you with your all educational needs. We provide university-based homework help that mainly includes United States (USA) university assignment help, Canada university assignment help, United Kingdom (UK) university assignment help, Australia university assignment help, and many more all over the world. Our experts have successfully done this for the past several years. Visit us at https://www.cpphomeworkhelp.com/
I am Frank P. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Malacca, Malaysia. I have been helping students with their homework for the past 9 years. I solve homework related to C++ Programming .
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Jeremy P. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Loughborough University, UK. I have been helping students with their homework for the past 8 years. I solve homework related to C++ Programming .
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Thanasis F. I am an Online C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Harvard University. I have been helping students with their homework for the past 6 years. I solve homework related to Online C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Online C++ Homework.
I am Irene M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from from California, USA. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Jayson L. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 8 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Moffat K. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from London, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Daniel N. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of Leeds, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Jason B. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Princeton University, USA. I have been helping students with their homework for the past 5 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Thanasis F. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Harvard University. I have been helping students with their homework for the past 5 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Jeremy P. I am an Online C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Loughborough University, UK. I have been helping students with their homework for the past 9 years. I solve homework related to Online C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Online C++ Homework.
I am Leonard K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of Arkansas, USA. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Cage T. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of California, USA. I have been helping students with their homework for the past 6 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Bianca H. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from, the University of Nottingham, UK. I have been helping students with their homework for the past 7 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Stuart M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from, the University of Greenwich, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Josh U. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from St. Edward’s University, USA. I have been helping students with their homework for the past 5 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
1. For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at :- info@cpphomeworkhelp.com or
reach us at :- https://www.cpphomeworkhelp.com/
2. Problems
Initializing multidimensional arrays:
The examples of multidimensional arrays in lecture did not give the syntax for initializing
them. The way to assign a multidimensional array in the array declaration is as follows:
int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} };
Inside the inner braces, commas still separate individual numbers. Outside, they separate
rows of the array. After this declaration, matrix[0][1] will return the value 2.
Each one of the rows is initialized like a regular array. For instance, if instead of {1, 2, 3}
we’d put {1}, the second and third elements of the first row would have been initialized
to 0.
1. Write a program that declares the 2D array of student test grades shown below, and
stores the students’ averages in a 1D array. Each row in the 2D array represents the
grades of a particular student (their parents uncreatively named them Student 0,
Student 1, etc.). Output the array of averages.
int studentGrades[6][5] = { {97, 75, 87, 56, 88}, {76, 84, 88, 59, 99}, {85, 86, 82, 81, 88},
{95, 92, 97, 97, 44}, {66, 74, 82, 60, 85}, {82, 73, 96, 32, 77} };
cpphomeworkhelp.com
3. Multidimensional arrays as arguments:
The syntax for passing multidimensional arrays as arguments is very similar to that of
passing regular arrays. The main difference is that you need to include the number of
columns in the function definition. For instance, a function that takes a 2-dimensional
array with 3 columns might be declared as follows:
void func( int array[][3], const int rows, const int columns ) {…}
2. Write a function based on your program from question 1 to calculate a set of grade
averages. It should take a few arguments, including a 2D array of student grades and a
1D array to store the averages in. (Recall that arrays are passed by reference.) It should
return nothing.
3. Multidimensional arrays are often used to store game boards. A tic-tac-toe board is a
basic example: the board can be stored as a 2D array of integers, where a positive
number represents Player 1, a negative number represents Player 2, and 0 represents a
space not yet taken by either player. Write a void function printTTTBoard that takes such
a 2D array as an argument and prints the board as a series of X’s, O’s, or spaces,
separated horizontally by tabs and vertically by newlines. For instance, it should output
the following board for the array
cpphomeworkhelp.com
4. 4. Assume that the following variable declaration has already been made:
char *oddOrEven = "Never odd or even";
Write a single statement to accomplish each of the following tasks:
a. Print the 4th character in oddOrEven
b. Create a pointer to a char value named nthCharPtr that stores the memory address
of the 4th character in oddOrEven
c. Using pointer arithmetic, update nthCharPtr to point to the 7th character in
oddOrEven
d. Print the value currently pointed to by nthCharPtr
e. Create a new pointer to a pointer (a char ** – yes, those are legal too!) named
pointerPtr that points to nthCharPtr
f. Print the value stored in pointerPtr
g. Update nthCharPtr to point to the next character in oddOrEven (i.e. one character
past the location it currently points to)
h. Using pointer arithmetic, print out how far away from the character currently
pointed to by nthCharPtr is from the start of the string
cpphomeworkhelp.com
{ {0, -1, 1}, {-1, 1, -1}, {-1, 1, 1} }:
O X
O X O
O X X
5. 5. Write a function swap that takes two arguments – pointers to character values –
and swaps the values of the variables these pointers point to. It should return nothing.
6. a. Write a function reverseString that takes one argument – a C-style string (a char
*) – and reverses it. The function should modify the values of the original string, and
should return nothing. (You may assume that you have a properly implemented swap
function as described in the previous problem. You may also use the strlen function,
which takes a char * and returns the length of the string. It is found in the cstring
standard header file.)
b. Indicate with two lines of code how you would declare a character array (a char[],
not a char*) containing the string "aibohphobia", and reverse it using reverseString.
Function pointers:
We mentioned in lecture that, since functions are really just blocks of instructions in
memory, you can create a pointer to a function. Schematically, the syntax for declaring
such a pointer is as follows:
return_type (*name)(argument_types);
The syntax for declaring the pointer is identical to the syntax for declaring a function,
except that where you’d put the name of the function in the function definition, you
put (*pointerName). To give an example:
cpphomeworkhelp.com
6. void (*functionPtr)(int, char) = &someFunction; // & is optional
Here, we declare a function pointer named functionPtr which points to some function
named someFunction. That function must be a void function that takes as arguments
one int and one char. Once we’ve declared functionPtr as a function pointer, we can
use it to call the function it points to simply by writing something like functionPtr(1,
'a').
7. a. Define two functions, cmpAscending and cmpDescending. Each should take two
integers. cmpAscending should return true if the first integer is greater than the second
and false otherwise. cmpDescending should do the reverse. Each one should be no
more than 3 lines of code.
b. One common application of function pointers is sorting – you can pass a function
pointer to a sorting function to decide whether to sort in ascending or descending
order. Extract the nested loop from the bubble sort code snippet from the Lecture 4
notes and place it into its own function. The function should take 3 arguments: an
integer array, the length of the array, and a function pointer. The function pointer (call
it comparator) should be of a type that points to a function that takes two integers and
returns a boolean. Modify the sorting code snippet to use comparator to compare
values for sorting, and show how you’d call your sort function with either
cmpDescending or cmpAscending.
cpphomeworkhelp.com
7. 8. Write a line to accomplish each of the following tasks. You will want to look up the
documentation for string functions online. (Recall that the way to call a function on a
string variable is, for instance, myString.find("a"). Also note that the usual cin and cout
syntaxes work for strings, but cin will stop reading at the first whitespace character.)
a. Declare a variable papayaWar of type string (assuming header file <string> has
been included). Initialize it to the value "No, sir, away! A papaya war is on!"
b. Print the index of the first instance of the exclamation point character in
papayaWar.
c. Print the length of the papayaWar string.
d. Print the last 5 characters of papayaWar.
e. Replace the contents of the string with a string that the user enters.
f. Append the string "rotator" to the end of papayaWar.
g. Print the contents of papayaWar.
cpphomeworkhelp.com
8. 1. #include <iostream>
using namespace std;
int main() {
int grades[6][5] = { {97, 75, 87, 56, 88},
{76, 84, 88, 59, 99}, {85, 86, 82, 81, 88},
{95, 92, 97, 97, 44}, {66, 74, 82, 60, 85},
{82, 73, 96, 32, 77} };
double averages[6];
for (int i = 0; i < 6; i++) {
int sum = 0;
for (int j = 0; j < 5; j++)
{
sum += grades[i][j];
}
averages[i] = sum/5.0;
}
for (int k = 0; k < 6; k++)
cout << "Student " << k
<< " has an average of " << averages[k] << endl;
return 0;
}
cpphomeworkhelp.com
Solutions
9. 2. void average( int grades[][5],
const int rows, const int columns, double averages[] ) {
for (int i = 0; i < rows; i++) {
int sum = 0;
for (int j = 0; j < columns; j++) {
sum += grades[i][j];
}
average [i] = sum / static_cast<double>(columns);
}
}
3. void printTTTBoard(int array[][3]) {
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
cout << (array[i][j] > 0 ? 'X' :
(array[i][j] == 0 ? ' ' : 'O') ) << 't';
}
cout << endl;
}
}
cpphomeworkhelp.com
10. 4. a. cout << oddOrEven[3]; // or cout << *(oddOrEven + 3);
b. char *nthCharPtr = oddOrEven + 3; (or, less preferably, &oddOrEven[3])
c. nthCharPtr += 3;
d. cout << *nthCharPtr;
e. char **pointerPtr = &nthCharPtr;
f. cout << pointerPtr;
g. nthCharPtr++; h.
h. cout << nthCharPtr - oddOrEven;
5. void swap( char *xPtr, char *yPtr ) {
char temp = *xPtr;
*xPtr = *yPtr;
*yPtr = temp;
}
6. a. void reverseString ( char string[] ) {
int stringLen = strlen(string);
for (int x=0; x< stringLen/2; x++) {
int y = stringLen-x-1;
swap (string[x], string[y]);
}
}
cpphomeworkhelp.com
11. b. char aibophobia[12] =
{'a', 'i', 'b', 'o', 'h', 'p', 'h', 'o', 'b', 'o', 'a', '0');
reverseString(aibophobia);
7. bool cmpAscending(int a, int b) {
return a < b;
}
bool cmpDescending(int a, int b) {
return a > b;
}
void sort(int arr[], const int arrLen,
bool (*comparator)(int,int)) {
for(int i = 0; i < arrLen; i++) {
for(int j = 0; j < i; j++) {
if( comparator(arr[i],arr[j]) ) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
cpphomeworkhelp.com
12. 8. a. string papayaWar = "No, sir, away! A papaya war is on!";
b. cout << papayaWar.find('!'); // or find("!")
c. cout << papayaWar.length();
d. cout << papayaWar.substr( papayaWar.length() - 5 );
or, less preferably,
cout << papayaWar.substr( 29 );
e. getline(cin, papayaWar); // or cin >> papayaWar, but that
// will stop at whitespace
f. papayaWar.append("rotator"); // or papayaWar += "rotator";
g. cout << papayaWar;
cpphomeworkhelp.com