change wrong - Programming
Corrected errors to correct. This is the C ++ language, which is very simple, only need to modify the errors
inclass_c04_dynamic_allocation.docx
c03_c___arrays_and_pointers_515.pptx
c04_c___storage_515.pptx
Unformatted Attachment Preview
CS 515 Exercise C04: Dynamic allocation
_____ /50
Names: __________________________________________ Wildcats ID’s : __________________________
Lecture Section: 01 / 02 (circle one)
Question: Is there any memory error in the code below? If so, how would you fix it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include
using namespace std;
void populate(int *arrayToPopulate, int arraySize);
int main()
{
int * ptr;
ptr = new int[100];
populate(ptr, 100);
for(int i=0; i<100; i++)
cout << ptr[i] << endl;
delete [] ptr;
return 0;
}
void populate(int *arr, int size)
{
for(int i=0; i 53.22)
if (temp2 > *temp_ptr)
*temp_ptr = temp2;
temp1 = 98.6
28
Example using *
plantA
• Example with an int
5
max
int plantA = 5;
plantB
int plantB = 8;
8
int *max = &plantA
(5 < 8)
if (*max < plantB)
8
max = &plantB
cout << Max value = << *max << endl;
29
The * means two different things
This is ok…
int n1 = 10;
int *ptr = &n1
But then this isn’t…
*ptr = &n1
30
You can have pointers to pointers
• It’s ok to have things that are pointers to int *,
for example
int n1 = 10;
int *ptr = &n1
int **pptr = &ptr
cout << **pptr << endl;
pptr
ptr
10
n1
10
31
Outline
• C++ Arrays
• Arrays as function parameters
• Common array errors
• C++ Pointers: Reference, dereference operators
• C-style strings
• Pointers and arrays
• Pass-by-value vs. Pass-by-reference
32
Built-in strings are arrays of char
• Declaring a string variable:
char username[50];
• String constants appear between double-quotes:
George
\n\%c
X
1 2 buckle my shoe
=====<>=====
• Initializing a string variable:
char country[10] = U.S.A.;
char sizedByInitializer[] = Hello;
33
Strings are null-terminated
• Logical size of a string indicated by a special
character ‘\0’ (null)
• All strings must have a null terminator
• Add +1 to size needed for largest string
char country[13] = Uzbekistan;
U
z
b
e
k
i
s
t
a
n
\0
0
1
2
3
4
5
6
7
8
9
10
11
12
char sizedByInitializer[] = Hello;
H
e
l
l
o
\0
0
1
2
3
4
5
34
String length vs. array size
• String length: the number of characters up to (but
not including) ‘\0’
• Logical size: # characters including ‘\0’
• Actual size: # chars set aside for the variable holding
the string (>= logical size)
char country[13] = Uzbekistan;
U
z
b
e
k
i
s
t
a
n
\0
0
1
2
3
4
5
6
7
8
9
10
11
12
35
String operations
• “Normal” operators work on pointers
• To get string functions, need
#include
• Some valid operations on strings:
• Assignment:
strcpy(s1, s2);
copy string from s2 into s1
• Test of equality/order: strcmp(s1, s2)
<0 if
s1 < s2 (s1 is before s2)
0 if
s1 == s2
>0 if
s1 > s2 (s1 is after s2)
36
Running example…
char s1[10] = ;
\0
char s2[10] = Hello;
H
e
l
l
o
\0
l
i
char s3[] = Charlie;
C
h
a
r
e
\0
int x;
37
Running example…
char s1[10] = ;
char s2[10] = Hello;
char s3[] = Charlie;
int x;
s1
strcpy(s1, s3); C h a
r
l
i
e
\0
x
x = strcmp(s1, s2);
x = strcmp(s2, s1);
x = strcmp(s1, s1);
-1
x
1
x
0
38
More string operations
s1
C
h
a
r
l
i
e
\0
• Get the length of a string
x
x = strlen(s1);
7
• Concatenate strings
strcat(s1, s);
s1
C
h
a
r
l
i
e
s
\0
39
Can I still index like an array?
• Yes
s1
s1[5] = e;
C
h
a
r
l
e
e
s
\0
s1[6] = s;
C
h
a
r
l
e
s
s
\0
s1[8] = \0;
C
h
a
r
l
e
s
\0 \0
r
D
El
e
e
s
for (x = 0; x < 5; x++)
s1[x] = A + x;
s1
C
A
h
B
a
C
\0
40
Outline
• C++ Arrays
• Arrays as function parameters
• Common array errors
• C++ Pointers: Reference, dereference operators
• C-style strings
• Pointers and arrays
• Pass-by-value vs. Pass-by-reference
41
Arrays are actually special pointers
• C++ allows arrays to be treated like pointers
• C++ allows pointers to be treated like arrays
• Can use pointers to char’s like a string
char brackishCat[] = Brackish water;
char freshCat[] = Fresh water;
char *category = brackishCat;
cout << category << endl;
Output:
category = freshCat;
Brackish water
Fresh!water
category[5] = !;
cout << category << endl;
42
Arrays of arrays using pointers
• If we want an array of these sorts of array pointers
can do this (there are other options, too):
char *categories[MAX_CATEGORIES];
categories[0] = brackishCat;
categories[1] = freshCat;
categories[2] = Salt water;
• Note—last one is assigning pointer to a character
constant (this is legal!)
43
Command-line arguments
• You might see this in programs…
int main(int argc, char ** argv)…
int main(int argc, char * argv[])…
• argc is the number of arguments passed
• argv is array of C-style strings
• Sample command-line:
\% a.out file1.txt file2.txt output.txt
argv[0]
argv[1]
argv[2]
argv[3]
44
You can do math on pointers
• Adding 1 to a pointer really adds the size of the type
it’s pointing to
• So if you have
int x[5] = {5, 10, 15, 20, 25};
int *p = x;
• Then the following are equivalent
cout
cout
cout
cout
<<
<<
<<
<<
x[2];
p[2];
*(p + 2);
(p + 1)[1];
45
You can change pointers using math
• Simply shifts pointer over as if in an array
int a[5] = {12, 5, 7, 19, 22};
int b = 8;
int *p = a;
p++;
p
b
a
p--;
8 12 5
p += 3;
p -= 4;
*p = *(p + 4);
7 19 22
46
Outline
• C++ Arrays
• Arrays as function parameters
• Common array errors
• C++ Pointers: Reference, dereference operators
• C-style strings
• Pointers and arrays
• Pass-by-value vs. Pass-by-reference
47
Passing conventions
• Pass-by-value: passing copies of values to a
function
• The function can use the values, but cannot change the
original values in the calling function
• What happens “normally”
• Pass-by-reference: passing the address of values to
a function
• The function can use the values, and any changes made
are reflected in the calling function
• What happens with parameters that are arrays & pointers
48
Pointers as parameters
• Function header: just use the star as in a variable
declaration
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
49
Calling functions with pointer arg’s
• Note that when we call a function like swap, we
need to pass the addresses of our variables
…
int x = 7;
int y = 13;
swap(&x, &y);
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
50
Also… Reference notation
• C++ reference declaration simplifies code a bit…
void swap(int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int main() {
int x = 7;
int y = 13;
swap(x, y);
return 0
}
• Really uses address, but acts like direct variable
51
Reference notation
• Could do this within a function as well
int main(int argc, char *argv[])
{
int a = 5;
int *b = &a
b
int &r = a;
r = 7;
}
a
5
7
r
• Reference acts like another name for the variable
52
Reference declaration errors
• The following declarations of r would all be invalid
int &r1
//nothing to refer to
int &r2 = 10; //10 has no memory location
double d;
int &r3 = d; //d is the wrong type
53
Summary
• C++ Arrays—grouping of all the same type
• C++ Pointers—way to refer to other variables
• Debuggers (like gdb)—way to find memory errors
• C-style strings
• Pass-by-value & Pass-by-reference
54
C++ Storage
Recycling and Rezoning
Weiss 1.5.1 (again)
Problems addressed
• How to create variables we don’t know we need
until run-time
• “My code can handle 100 stores, but not 101”
• How to free up variables to make room for more
• How the compiler manages “local” variables
• How to protect memory from modification
• What if you want to…? (From “Pointers” slides)
• Create arrays of a size determined at run-time
2
First: three main categories
Storage type impacts the life-span of variables
• Static
variables exist for the life of the process
• Automatic
• variables exist for the life of a function/method
• Dynamic
• programmer controls life span of variables
3
Plan of attack
• Dynamic storage (manual memory management)
• new and delete
• Example of dynamic 2-D array
• Static storage
• Automatic storage
• const storage modifier
• Storage errors
4
The new operator
• new allocates new (unnamed) storage in memory
int *ptr = new int;
*ptr = 5;
ptr
5
?
• Allocates size of type (in bytes)
• char gets one byte
• float get 4 bytes
• Etc.
• Optional initialization using parentheses or braces
int *ptr = new int(5); //or new int{5}
5
The delete operator
• Delete deallocates (releases) storage for later reuse
int *ptr = new int(5);
delete ptr;
ptr
5
• Pointer still has same address…
• …but address is now invalid
• Later call to new could repurpose the memory for
storage of another type
6
Why do we need delete?
• Memory is not limitless—you can run out
• If you lose your pointer, can’t free it later
• How can you lose your pointer?
• Pointer goes out of scope
• Pointer used in another call to new
• Note: programmer controls life of dynamic storage
7
Array versions of new and delete
• Array variant of new allocates swath of storage
int *ptr = new int[152];
ptr
• All the same type
• Can initialize using braces (C++11 and later)
?
?
int *ptr = new int[152]{6, 3, 4};
• Must be matched with array variant of delete
delete [] ptr;
8
?
Example of Dynamic 2D Array
• Need to allocate row pointers first
• then each row (could make different sizes…)
int rows = 0; int cols = 0; int i = 0;
double **temps = NULL;
cout << What 2D size do you want? ;
temps
cin >> rows >> cols;
temps = new double *[rows];
for (i = 0; i < rows; i++)
temps[i] = new double[cols];
9
Remember to initialize, delete
temps = new double *[rows];
for (i = 0; i < rows; i++)
{
temps[i] = new double[cols];
for (int j = 0; j < cols; j++)
temps[i][j] = 0.0;
}
temps
…
for (i = 0; i < rows; i++)
delete [] temps[i];
delete [] temps;
10
Plan of attack
• Dynamic storage (manual memory management)
• new and delete
• Example of dynamic 2-D array
• Static storage
• Automatic storage
• const storage modifier
• Storage errors
11
Static storage
• C/C++ allows global variables (but I don’t)
• Declared outside of a function or class
• Exist for the life of the process
• You can also declare variables static
static int num_instances;
• In a function a static variable…
• retains its value from call to call
• can only be accessed from within the function
• In a class, a static variable…
• can be accessed by any instance of the class
12
Life of static storage
• Initialization
• Can only be initialized once
• Global/class variables initialized first (“before” main)
• Function/method variables initialized on first call
• Can be changed any time (if in scope)
• Deallocation
• Only happens if constructor called in the first place
• Happens upon program exit (“after” the return in main)
13
Automatic storage
• Local variables and function parameters are
automatically allocated in a part of memory called
the stack
• Long stretch of memory used in terms of frames
• Add one frame for each function entered (allocating
variables)
• Remove the frame when function returns
(deallocating variables)
• In contrast, dynamic storage occurs in the heap
• A larger area of storage for use with new and ...
Purchase answer to see full
attachment
CATEGORIES
Economics
Nursing
Applied Sciences
Psychology
Science
Management
Computer Science
Human Resource Management
Accounting
Information Systems
English
Anatomy
Operations Management
Sociology
Literature
Education
Business & Finance
Marketing
Engineering
Statistics
Biology
Political Science
Reading
History
Financial markets
Philosophy
Mathematics
Law
Criminal
Architecture and Design
Government
Social Science
World history
Chemistry
Humanities
Business Finance
Writing
Programming
Telecommunications Engineering
Geography
Physics
Spanish
ach
e. Embedded Entrepreneurship
f. Three Social Entrepreneurship Models
g. Social-Founder Identity
h. Micros-enterprise Development
Outcomes
Subset 2. Indigenous Entrepreneurship Approaches (Outside of Canada)
a. Indigenous Australian Entrepreneurs Exami
Calculus
(people influence of
others) processes that you perceived occurs in this specific Institution Select one of the forms of stratification highlighted (focus on inter the intersectionalities
of these three) to reflect and analyze the potential ways these (
American history
Pharmacology
Ancient history
. Also
Numerical analysis
Environmental science
Electrical Engineering
Precalculus
Physiology
Civil Engineering
Electronic Engineering
ness Horizons
Algebra
Geology
Physical chemistry
nt
When considering both O
lassrooms
Civil
Probability
ions
Identify a specific consumer product that you or your family have used for quite some time. This might be a branded smartphone (if you have used several versions over the years)
or the court to consider in its deliberations. Locard’s exchange principle argues that during the commission of a crime
Chemical Engineering
Ecology
aragraphs (meaning 25 sentences or more). Your assignment may be more than 5 paragraphs but not less.
INSTRUCTIONS:
To access the FNU Online Library for journals and articles you can go the FNU library link here:
https://www.fnu.edu/library/
In order to
n that draws upon the theoretical reading to explain and contextualize the design choices. Be sure to directly quote or paraphrase the reading
ce to the vaccine. Your campaign must educate and inform the audience on the benefits but also create for safe and open dialogue. A key metric of your campaign will be the direct increase in numbers.
Key outcomes: The approach that you take must be clear
Mechanical Engineering
Organic chemistry
Geometry
nment
Topic
You will need to pick one topic for your project (5 pts)
Literature search
You will need to perform a literature search for your topic
Geophysics
you been involved with a company doing a redesign of business processes
Communication on Customer Relations. Discuss how two-way communication on social media channels impacts businesses both positively and negatively. Provide any personal examples from your experience
od pressure and hypertension via a community-wide intervention that targets the problem across the lifespan (i.e. includes all ages).
Develop a community-wide intervention to reduce elevated blood pressure and hypertension in the State of Alabama that in
in body of the report
Conclusions
References (8 References Minimum)
*** Words count = 2000 words.
*** In-Text Citations and References using Harvard style.
*** In Task section I’ve chose (Economic issues in overseas contracting)"
Electromagnetism
w or quality improvement; it was just all part of good nursing care. The goal for quality improvement is to monitor patient outcomes using statistics for comparison to standards of care for different diseases
e a 1 to 2 slide Microsoft PowerPoint presentation on the different models of case management. Include speaker notes... .....Describe three different models of case management.
visual representations of information. They can include numbers
SSAY
ame workbook for all 3 milestones. You do not need to download a new copy for Milestones 2 or 3. When you submit Milestone 3
pages):
Provide a description of an existing intervention in Canada
making the appropriate buying decisions in an ethical and professional manner.
Topic: Purchasing and Technology
You read about blockchain ledger technology. Now do some additional research out on the Internet and share your URL with the rest of the class
be aware of which features their competitors are opting to include so the product development teams can design similar or enhanced features to attract more of the market. The more unique
low (The Top Health Industry Trends to Watch in 2015) to assist you with this discussion.
https://youtu.be/fRym_jyuBc0
Next year the $2.8 trillion U.S. healthcare industry will finally begin to look and feel more like the rest of the business wo
evidence-based primary care curriculum. Throughout your nurse practitioner program
Vignette
Understanding Gender Fluidity
Providing Inclusive Quality Care
Affirming Clinical Encounters
Conclusion
References
Nurse Practitioner Knowledge
Mechanics
and word limit is unit as a guide only.
The assessment may be re-attempted on two further occasions (maximum three attempts in total). All assessments must be resubmitted 3 days within receiving your unsatisfactory grade. You must clearly indicate “Re-su
Trigonometry
Article writing
Other
5. June 29
After the components sending to the manufacturing house
1. In 1972 the Furman v. Georgia case resulted in a decision that would put action into motion. Furman was originally sentenced to death because of a murder he committed in Georgia but the court debated whether or not this was a violation of his 8th amend
One of the first conflicts that would need to be investigated would be whether the human service professional followed the responsibility to client ethical standard. While developing a relationship with client it is important to clarify that if danger or
Ethical behavior is a critical topic in the workplace because the impact of it can make or break a business
No matter which type of health care organization
With a direct sale
During the pandemic
Computers are being used to monitor the spread of outbreaks in different areas of the world and with this record
3. Furman v. Georgia is a U.S Supreme Court case that resolves around the Eighth Amendments ban on cruel and unsual punishment in death penalty cases. The Furman v. Georgia case was based on Furman being convicted of murder in Georgia. Furman was caught i
One major ethical conflict that may arise in my investigation is the Responsibility to Client in both Standard 3 and Standard 4 of the Ethical Standards for Human Service Professionals (2015). Making sure we do not disclose information without consent ev
4. Identify two examples of real world problems that you have observed in your personal
Summary & Evaluation: Reference & 188. Academic Search Ultimate
Ethics
We can mention at least one example of how the violation of ethical standards can be prevented. Many organizations promote ethical self-regulation by creating moral codes to help direct their business activities
*DDB is used for the first three years
For example
The inbound logistics for William Instrument refer to purchase components from various electronic firms. During the purchase process William need to consider the quality and price of the components. In this case
4. A U.S. Supreme Court case known as Furman v. Georgia (1972) is a landmark case that involved Eighth Amendment’s ban of unusual and cruel punishment in death penalty cases (Furman v. Georgia (1972)
With covid coming into place
In my opinion
with
Not necessarily all home buyers are the same! When you choose to work with we buy ugly houses Baltimore & nationwide USA
The ability to view ourselves from an unbiased perspective allows us to critically assess our personal strengths and weaknesses. This is an important step in the process of finding the right resources for our personal learning style. Ego and pride can be
· By Day 1 of this week
While you must form your answers to the questions below from our assigned reading material
CliftonLarsonAllen LLP (2013)
5 The family dynamic is awkward at first since the most outgoing and straight forward person in the family in Linda
Urien
The most important benefit of my statistical analysis would be the accuracy with which I interpret the data. The greatest obstacle
From a similar but larger point of view
4 In order to get the entire family to come back for another session I would suggest coming in on a day the restaurant is not open
When seeking to identify a patient’s health condition
After viewing the you tube videos on prayer
Your paper must be at least two pages in length (not counting the title and reference pages)
The word assimilate is negative to me. I believe everyone should learn about a country that they are going to live in. It doesnt mean that they have to believe that everything in America is better than where they came from. It means that they care enough
Data collection
Single Subject Chris is a social worker in a geriatric case management program located in a midsize Northeastern town. She has an MSW and is part of a team of case managers that likes to continuously improve on its practice. The team is currently using an
I would start off with Linda on repeating her options for the child and going over what she is feeling with each option. I would want to find out what she is afraid of. I would avoid asking her any “why” questions because I want her to be in the here an
Summarize the advantages and disadvantages of using an Internet site as means of collecting data for psychological research (Comp 2.1) 25.0\% Summarization of the advantages and disadvantages of using an Internet site as means of collecting data for psych
Identify the type of research used in a chosen study
Compose a 1
Optics
effect relationship becomes more difficult—as the researcher cannot enact total control of another person even in an experimental environment. Social workers serve clients in highly complex real-world environments. Clients often implement recommended inte
I think knowing more about you will allow you to be able to choose the right resources
Be 4 pages in length
soft MB-920 dumps review and documentation and high-quality listing pdf MB-920 braindumps also recommended and approved by Microsoft experts. The practical test
g
One thing you will need to do in college is learn how to find and use references. References support your ideas. College-level work must be supported by research. You are expected to do that for this paper. You will research
Elaborate on any potential confounds or ethical concerns while participating in the psychological study 20.0\% Elaboration on any potential confounds or ethical concerns while participating in the psychological study is missing. Elaboration on any potenti
3 The first thing I would do in the family’s first session is develop a genogram of the family to get an idea of all the individuals who play a major role in Linda’s life. After establishing where each member is in relation to the family
A Health in All Policies approach
Note: The requirements outlined below correspond to the grading criteria in the scoring guide. At a minimum
Chen
Read Connecting Communities and Complexity: A Case Study in Creating the Conditions for Transformational Change
Read Reflections on Cultural Humility
Read A Basic Guide to ABCD Community Organizing
Use the bolded black section and sub-section titles below to organize your paper. For each section
Losinski forwarded the article on a priority basis to Mary Scott
Losinksi wanted details on use of the ED at CGH. He asked the administrative resident