SlideShare a Scribd company logo
1 of 11
#include <iostream>
#include <cstring>
using namespace std;
//PROJECT 1 STUDENT FILE
//Postcondition: The value in parameter a contains the value that
was in parameter b and
//the value of parameter b contains the value that was in
parameter a
template <class type> void swapIt(type &a, type &b);
//Postcondition: Returns true if all characters in the string
(dynamic character array)
//are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the
function returns false
bool isDigitString(const char *);
//Postcondition: Reverses the order of the characters in the
//string (dynamic character array)
void reverse(char *);
//Postcondition: Prints the addresses of each memory location of
the dynamic array
template <class type> void printAddresses(type *, int);
//Postcondition: Prints the ASCII decimal code for each
character in the
//string (dynamic character array)
void printASCII(char *);
//test drivers for functions
void test_isDigitString();
void test_reverse(char *);
int main()
{
//you may want to comment out certain code below so you can
do
//more specific testing or add your own testing
//testing swapIt function with integers
int x = 2, y = 8;
cout << "Before swap x = " << x << " and y = " << y <<
endl;
swapIt(x,y);
cout << "After swap x = " << x << " and y = " << y <<
endl;
//testing swapIt function with booleans
bool a = true, b = false;
cout << boolalpha;
cout << "Before swap x = " << a << " and y = " << b <<
endl;
swapIt(a,b);
cout << "After swap x = " << a << " and y = " << b <<
endl;
//test if isDigitString function is working properly
test_isDigitString();
cout << endl;
//test if reverse function is working properly
char str[] = "This is a test";
test_reverse(str);
cout << endl;
//test if printAddresses function is working properly
printAddresses(str, strlen(str));
cout << endl;
//test if printASCII function is working properly
printASCII(str);
cout << endl;
}
//Postcondition: The value in parameter a contains the value that
was in parameter b and
//the value of parameter b contains the value that was in
parameter a
template <class type>
void swapIt(type &a, type&b)
{
//FILL IN NECESSARY CODE
}
//Postcondition: Returns true if all characters in the string
(dynamic character array)
//are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the
function returns false
bool isDigitString(const char *theString)
{
//FILL IN NECESSARY CODE
}
//Postcondition: Reverses the order of the characters in the
//string (dynamic character array)
void reverse(char *theString)
{
//FILL IN NECESSARY CODE
}
//Postcondition: Prints the addresses of each memory location of
the dynamic array
template <class type>
void printAddresses(type *item, int n)
{
//FILL IN NECESSARY CODE
}
//Postcondition: Prints the ASCII decimal code for each
character in the
//string (dynamic character array)
void printASCII(char *theString)
{
//FILL IN NECESSARY CODE
}
void test_isDigitString()
{
bool tryAgain = false;
int size;
cout << "Enter the maximum size for your string. ";
cin >> size;
char *str = new char[size];
do
{
cout << "Enter a positive integer. ";
cin >> str;
if(isDigitString(str))
{
cout << "You have entered the positive integer " <<
str << endl;
tryAgain = false;
}
else
{
cout << "You have entered incorrect data. Please try
again.  ";
tryAgain = true;
}
}while(tryAgain);
delete str;
}
void test_reverse(char *theString)
{
reverse(theString);
cout << "Your string in reverse is: " << theString << endl;
}
Solution
#include <iostream>
#include <cstring>
using namespace std;
//PROJECT 1 STUDENT FILE
//Postcondition: The value in parameter a contains the value
that was in parameter b and
//the value of parameter b contains the value that was in
parameter a
template <class type> void swapIt(type &a, type &b);
//Postcondition: Returns true if all characters in the string
(dynamic character array)
//are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the
function returns false
bool isDigitString(const char *);
//Postcondition: Reverses the order of the characters in the
//string (dynamic character array)
void reverse(char *);
//Postcondition: Prints the addresses of each memory location
of the dynamic array
template <class type> void printAddresses(type *, int);
//Postcondition: Prints the ASCII decimal code for each
character in the
//string (dynamic character array)
void printASCII(char *);
//test drivers for functions
void test_isDigitString();
void test_reverse(char *);
int main()
{
//you may want to comment out certain code below so you can
do
//more specific testing or add your own testing
//testing swapIt function with integers
int x = 2, y = 8;
cout << "Before swap x = " << x << " and y = " << y <<
endl;
swapIt(x,y);
cout << "After swap x = " << x << " and y = " << y << endl;
//testing swapIt function with booleans
bool a = true, b = false;
cout << boolalpha;
cout << "Before swap x = " << a << " and y = " << b <<
endl;
swapIt(a,b);
cout << "After swap x = " << a << " and y = " << b << endl;
//test if isDigitString function is working properly
test_isDigitString();
cout << endl;
//test if reverse function is working properly
char str[] = "This is a test";
test_reverse(str);
cout << endl;
//test if printAddresses function is working properly
printAddresses(str, strlen(str));
cout << endl;
//test if printASCII function is working properly
printASCII(str);
cout << endl;
}
//Postcondition: The value in parameter a contains the value
that was in parameter b and
//the value of parameter b contains the value that was in
parameter a
template <class type>
void swapIt(type &a, type&b)
{
//FILL IN NECESSARY CODE
type temp;
temp = a;
a = b;
b = temp;
}
//Postcondition: Returns true if all characters in the string
(dynamic character array)
//are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the
function returns false
bool isDigitString(const char *theString)
{
//FILL IN NECESSARY CODE
int i = 0;
while(*theString != '0')
if(!isdigit(*theString))
return false;
return true;
}
//Postcondition: Reverses the order of the characters in the
//string (dynamic character array)
void reverse(char *theString)
{
//FILL IN NECESSARY CODE
int len = strlen(theString);
for(int i = len -1 ; i >= 0; i--)
cout<<*theString<<endl;
}
//Postcondition: Prints the addresses of each memory location
of the dynamic array
template <class type>
void printAddresses(type *item, int n)
{
//FILL IN NECESSARY CODE
for(int i = 0; i < n; i++)
cout<<(item + i)<<" ";
cout<<endl;
}
//Postcondition: Prints the ASCII decimal code for each
character in the
//string (dynamic character array)
void printASCII(char *theString)
{
//FILL IN NECESSARY CODE
int i = 0;
while(*(theString + i) != '0')
cout<<*(theString + i)<<" ";
cout<<endl;
}
void test_isDigitString()
{
bool tryAgain = false;
int size;
cout << "Enter the maximum size for your string. ";
cin >> size;
char *str = new char[size];
do
{
cout << "Enter a positive integer. ";
cin >> str;
if(isDigitString(str))
{
cout << "You have entered the positive integer " << str <<
endl;
tryAgain = false;
}
else
{
cout << "You have entered incorrect data. Please try again. 
";
tryAgain = true;
}
}while(tryAgain);
delete str;
}
void test_reverse(char *theString)
{
reverse(theString);
cout << "Your string in reverse is: " << theString << endl;
}

More Related Content

Similar to #include iostream #include cstringusing namespace std;PR.docx

6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
Do the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdfDo the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdffacevenky
 
The Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdfThe Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdfinfo785431
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)David Atchley
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docxAbdulrahman890100
 
Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfinfo382133
 
#pragma once#include iostreamclass String { private .docx
#pragma once#include iostreamclass String { private  .docx#pragma once#include iostreamclass String { private  .docx
#pragma once#include iostreamclass String { private .docxgertrudebellgrove
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questionsFarag Zakaria
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2Mohamed Krar
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptxJawadTanvir
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
Please answer as soon as possibleCharacter.cpphpp givenCharact.pdf
Please answer as soon as possibleCharacter.cpphpp givenCharact.pdfPlease answer as soon as possibleCharacter.cpphpp givenCharact.pdf
Please answer as soon as possibleCharacter.cpphpp givenCharact.pdfrmwaterlife
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructsGopikaS12
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 

Similar to #include iostream #include cstringusing namespace std;PR.docx (20)

6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Computer programming 2 Lesson 11
Computer programming 2  Lesson 11Computer programming 2  Lesson 11
Computer programming 2 Lesson 11
 
Do the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdfDo the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdf
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
The Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdfThe Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdf
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)Idiomatic Javascript (ES5 to ES2015+)
Idiomatic Javascript (ES5 to ES2015+)
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
 
Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdf
 
#pragma once#include iostreamclass String { private .docx
#pragma once#include iostreamclass String { private  .docx#pragma once#include iostreamclass String { private  .docx
#pragma once#include iostreamclass String { private .docx
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questions
 
Strings
StringsStrings
Strings
 
Csharp In Detail Part2
Csharp In Detail Part2Csharp In Detail Part2
Csharp In Detail Part2
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Please answer as soon as possibleCharacter.cpphpp givenCharact.pdf
Please answer as soon as possibleCharacter.cpphpp givenCharact.pdfPlease answer as soon as possibleCharacter.cpphpp givenCharact.pdf
Please answer as soon as possibleCharacter.cpphpp givenCharact.pdf
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 

More from ajoy21

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxajoy21
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxajoy21
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxajoy21
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxajoy21
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxajoy21
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxajoy21
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxajoy21
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxajoy21
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxajoy21
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxajoy21
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxajoy21
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxajoy21
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxajoy21
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxajoy21
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxajoy21
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxajoy21
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 

#include iostream #include cstringusing namespace std;PR.docx

  • 1. #include <iostream> #include <cstring> using namespace std; //PROJECT 1 STUDENT FILE //Postcondition: The value in parameter a contains the value that was in parameter b and //the value of parameter b contains the value that was in parameter a template <class type> void swapIt(type &a, type &b); //Postcondition: Returns true if all characters in the string (dynamic character array) //are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the function returns false bool isDigitString(const char *); //Postcondition: Reverses the order of the characters in the //string (dynamic character array) void reverse(char *); //Postcondition: Prints the addresses of each memory location of the dynamic array template <class type> void printAddresses(type *, int); //Postcondition: Prints the ASCII decimal code for each character in the //string (dynamic character array) void printASCII(char *); //test drivers for functions void test_isDigitString(); void test_reverse(char *); int main() { //you may want to comment out certain code below so you can do //more specific testing or add your own testing //testing swapIt function with integers int x = 2, y = 8; cout << "Before swap x = " << x << " and y = " << y <<
  • 2. endl; swapIt(x,y); cout << "After swap x = " << x << " and y = " << y << endl; //testing swapIt function with booleans bool a = true, b = false; cout << boolalpha; cout << "Before swap x = " << a << " and y = " << b << endl; swapIt(a,b); cout << "After swap x = " << a << " and y = " << b << endl; //test if isDigitString function is working properly test_isDigitString(); cout << endl; //test if reverse function is working properly char str[] = "This is a test"; test_reverse(str); cout << endl; //test if printAddresses function is working properly printAddresses(str, strlen(str)); cout << endl; //test if printASCII function is working properly printASCII(str); cout << endl; } //Postcondition: The value in parameter a contains the value that was in parameter b and //the value of parameter b contains the value that was in parameter a template <class type> void swapIt(type &a, type&b)
  • 3. { //FILL IN NECESSARY CODE } //Postcondition: Returns true if all characters in the string (dynamic character array) //are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the function returns false bool isDigitString(const char *theString) { //FILL IN NECESSARY CODE } //Postcondition: Reverses the order of the characters in the //string (dynamic character array) void reverse(char *theString) { //FILL IN NECESSARY CODE } //Postcondition: Prints the addresses of each memory location of the dynamic array template <class type> void printAddresses(type *item, int n) { //FILL IN NECESSARY CODE } //Postcondition: Prints the ASCII decimal code for each character in the //string (dynamic character array) void printASCII(char *theString) { //FILL IN NECESSARY CODE
  • 4. } void test_isDigitString() { bool tryAgain = false; int size; cout << "Enter the maximum size for your string. "; cin >> size; char *str = new char[size]; do { cout << "Enter a positive integer. "; cin >> str; if(isDigitString(str)) { cout << "You have entered the positive integer " << str << endl; tryAgain = false; } else { cout << "You have entered incorrect data. Please try again. "; tryAgain = true; } }while(tryAgain); delete str; } void test_reverse(char *theString) { reverse(theString); cout << "Your string in reverse is: " << theString << endl;
  • 5. } Solution #include <iostream> #include <cstring> using namespace std; //PROJECT 1 STUDENT FILE //Postcondition: The value in parameter a contains the value that was in parameter b and //the value of parameter b contains the value that was in parameter a template <class type> void swapIt(type &a, type &b); //Postcondition: Returns true if all characters in the string (dynamic character array) //are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the function returns false bool isDigitString(const char *); //Postcondition: Reverses the order of the characters in the //string (dynamic character array) void reverse(char *); //Postcondition: Prints the addresses of each memory location
  • 6. of the dynamic array template <class type> void printAddresses(type *, int); //Postcondition: Prints the ASCII decimal code for each character in the //string (dynamic character array) void printASCII(char *); //test drivers for functions void test_isDigitString(); void test_reverse(char *); int main() { //you may want to comment out certain code below so you can do //more specific testing or add your own testing //testing swapIt function with integers int x = 2, y = 8; cout << "Before swap x = " << x << " and y = " << y << endl; swapIt(x,y); cout << "After swap x = " << x << " and y = " << y << endl; //testing swapIt function with booleans bool a = true, b = false; cout << boolalpha; cout << "Before swap x = " << a << " and y = " << b <<
  • 7. endl; swapIt(a,b); cout << "After swap x = " << a << " and y = " << b << endl; //test if isDigitString function is working properly test_isDigitString(); cout << endl; //test if reverse function is working properly char str[] = "This is a test"; test_reverse(str); cout << endl; //test if printAddresses function is working properly printAddresses(str, strlen(str)); cout << endl; //test if printASCII function is working properly printASCII(str); cout << endl; } //Postcondition: The value in parameter a contains the value that was in parameter b and //the value of parameter b contains the value that was in parameter a template <class type>
  • 8. void swapIt(type &a, type&b) { //FILL IN NECESSARY CODE type temp; temp = a; a = b; b = temp; } //Postcondition: Returns true if all characters in the string (dynamic character array) //are a numerical digit (0,1,2,3,4,5,6,7,8,9). Otherwise the function returns false bool isDigitString(const char *theString) { //FILL IN NECESSARY CODE int i = 0; while(*theString != '0') if(!isdigit(*theString)) return false; return true; } //Postcondition: Reverses the order of the characters in the //string (dynamic character array) void reverse(char *theString)
  • 9. { //FILL IN NECESSARY CODE int len = strlen(theString); for(int i = len -1 ; i >= 0; i--) cout<<*theString<<endl; } //Postcondition: Prints the addresses of each memory location of the dynamic array template <class type> void printAddresses(type *item, int n) { //FILL IN NECESSARY CODE for(int i = 0; i < n; i++) cout<<(item + i)<<" "; cout<<endl; } //Postcondition: Prints the ASCII decimal code for each character in the //string (dynamic character array) void printASCII(char *theString)
  • 10. { //FILL IN NECESSARY CODE int i = 0; while(*(theString + i) != '0') cout<<*(theString + i)<<" "; cout<<endl; } void test_isDigitString() { bool tryAgain = false; int size; cout << "Enter the maximum size for your string. "; cin >> size; char *str = new char[size]; do { cout << "Enter a positive integer. "; cin >> str; if(isDigitString(str)) { cout << "You have entered the positive integer " << str << endl;
  • 11. tryAgain = false; } else { cout << "You have entered incorrect data. Please try again. "; tryAgain = true; } }while(tryAgain); delete str; } void test_reverse(char *theString) { reverse(theString); cout << "Your string in reverse is: " << theString << endl; }