SlideShare a Scribd company logo
Can anyone fix this code, I use Visual Studios:
The Errors im getting is that it is not reverseing correctly,
And the line if (arr[i] == strRev[i])
gives me a error code C4700 uninitialized local variable 'strRev' used
This is the program that neeeds to be created:
In C++, with a myString.h, myStringImp.cpp, and main.cpp:
Design and implement a class myString:
-Use a dynamic array of char to store the characters of myString.
-Use an int to keep track of the length of myString.
-Provide a parameterized constructor that takes an initial string, a default constructor, destructor,
assignment operator, and copy constructor. All need to correctly handle the dynamic array.
-Also provide these member functions:
--length() //the length of myString
--isEqual() //if it is equal to another myString
--print() //output to a terminal cout or outFile
--reverse() //reverse the order of characters in myString
--isPalindrome() //if myString reads the same after being reversed
Here is the code that is broken:
C++ Code:
Header File:myString.h
#ifndef MYSTRING_H_INCLUDED
#define MYSTRING_H_INCLUDED
#include
using namespace std;
//Class definition
class myString
{
public:
//Char Array pointer
char *arr;
//Integer to hold length
int len;
//Default constructor
myString();
//Parameter constructor
myString(string str);
//Copy constructor
myString(const myString &obj);
//Overloading assignment operator
void operator=(const myString &obj);
//Destructor
~myString();
//Returns length
int length();
//Compares two string for equality
bool isEqual(myString &obj);
//Printing string to console
void print();
//Reversing the string
void reverse();
//Check for palindrome of current string and its reverse
bool isPalindrome();
};
#endif // MYSTRING_H_INCLUDED
Implementation File:myString.cpp
/* Implementation File */
#include
#include
#include "myString.h"
using namespace std;
//Default Constructor
myString :: myString()
{
//Initializing length to 0
len = 0;
arr = new char[0];
}
//Parameter constructor
myString :: myString(string str)
{
int i;
//Taking length
len = strlen(str.c_str());
//Allocating space
arr = new char[len+1];
//Copying characters
for(i=0; i arr[i] = str[i];
arr[i] = '0';
}
//Copy constructor
myString :: myString(const myString &obj)
{
//Fetching length
len = obj.len;
//Allocating memory
arr = new char[len];
//Assigning dynamic character arrays
*arr = *obj.arr;
}
//Assignment operator overloading
void myString :: operator=(const myString &obj)
{
//Fetching length
len = obj.len;
//Allocating memory
arr = new char[len];
//Assigning dynamic character arrays
*arr = *obj.arr;
}
//Destructor
myString :: ~myString()
{
//deallocates space
delete arr;
}
//Function that returns length of string
int myString ::length()
{
return len;
}
//Compares two strings and returns true if they are equal else false
bool myString::isEqual(myString &obj)
{
int i, cnt=0;
//Comparing lengths
if(len != (obj.len))
return false;
//Comparing character by character
for(i=0; i {
if(arr[i] == obj.arr[i])
cnt++;
}
//Return value
if(cnt == len)
return true;
else
return false;
}
//Function that prints the string to console
void myString::print()
{
int i;
cout << "  String: ";
//Printing character by character
for(i=0; i cout << arr[i];
cout << "  ";
}
//Function that reverses the string
void myString::reverse()
{
int i,j;
char *tmp;
tmp = new char[len];
//Reversing the array
for(i=len-1,j=0; i>=0; i--,j++)
tmp[j] = arr[i];
//Reallocating string
*arr = *tmp;
}
//Function that checks for palindrome of a string and its reverse
bool myString::isPalindrome()
{
char *strRev;
int i, cnt=0;
//Creating a string object
myString temp(arr);
//REversing the string
temp.reverse();
//Comparing character by character
for(i=0; i {
//Comparing char in both arrays
if(arr[i] == strRev[i])
cnt++;
}
//If all are matched return true else false
if(cnt == len)
return true;
else
return false;
}
Main File: main.cpp
#include
#include "myString.h"
using namespace std;
int main()
{
//creating myString object 1
myString obj1("madam");
cout << "  Object 1: ";
//Printing object 1
obj1.print();
//creating myString object 2
myString obj2("anil");
cout << "  Object 2: ";
//Printing object 2
obj2.print();
//Reversing object 2
obj2.reverse();
//Printing object 2 after reversing
cout << " After reversing: ";
obj2.print();
//Checking for palindrome of object 2 with its reverse
cout << " " << obj2.isPalindrome();
cout << endl;
return 0;
}
Solution
//Header File: myString.h
#ifndef MYSTRING_H_INCLUDED
#define MYSTRING_H_INCLUDED
#include
using namespace std;
//Class definition
class myString
{
public:
//Char Array pointer
char *arr;
//Integer to hold length
int len;
//Default constructor
myString();
//Parameter constructor
myString(string str);
//Copy constructor
myString(const myString &obj);
//Overloading assignment operator
void operator=(const myString &obj);
//Destructor
~myString();
//Returns length
int length();
//Compares two string for equality
bool isEqual(myString &obj);
//Printing string to console
void print();
//Reversing the string
void reverse();
//Check for palindrome of current string and its reverse
bool isPalindrome();
};
#endif // MYSTRING_H_INCLUDED
//Implementation File: myString.cpp
/* Implementation File */
#include
#include
#include
#include
#include
#include "myString.h"
using namespace std;
//Default Constructor
myString :: myString()
{
//Initializing length to 0
len = 0;
arr = new char[0];
}
//Parameter constructor
myString :: myString(string str)
{
int i;
//Taking length
len = strlen(str.c_str());
//Allocating space
arr = new char[len+1];
//Copying characters
for(i=0; i < len+1; i++)
arr[i] = str[i];
arr[i] = '0';
}
//Copy constructor
myString :: myString(const myString &obj)
{
//Fetching length
len = obj.len;
//Allocating memory
arr = new char[len];
//Assigning dynamic character arrays
*arr = *obj.arr;
}
//Assignment operator overloading
void myString :: operator=(const myString &obj)
{
//Fetching length
len = obj.len;
//Allocating memory
arr = new char[len];
//Assigning dynamic character arrays
*arr = *obj.arr;
}
//Destructor
myString :: ~myString()
{
//deallocates space
delete arr;
}
//Function that returns length of string
int myString ::length()
{
return len;
}
//Compares two strings and returns true if they are equal else false
bool myString::isEqual(myString &obj)
{
int i, cnt=0;
//Comparing lengths
if(len != (obj.len))
return false;
//Comparing character by character
for(i=0; i=0; i--,j++)
tmp[j] = arr[i];
//Reallocating string
strcpy(arr,tmp);
}
//Function that checks for palindrome of a string and its reverse
bool myString::isPalindrome()
{
int i,j;
int cnt=0;
char *tmp;
tmp = new char[len];
//Reversing the array
for(i=len-1,j=0; i>=0; i--,j++)
tmp[j] = arr[i];
//Comparing character by character
for(i=0; i
#include
#include
#include
#include
#include "myString.h"
using namespace std;
int main()
{
//creating myString object 1
myString obj1("madam");
cout << "  Object 1: ";
//Printing object 1
obj1.print();
//creating myString object 2
myString obj2("anil");
cout << "  Object 2: ";
//Printing object 2
obj2.print();
//Reversing object 2
obj2.reverse();
//Printing object 2 after reversing
cout << " After reversing: ";
obj2.print();
//Checking for palindrome of object 2 with its reverse
cout << " ";
obj2.print();
if(obj2.isPalindrome() == true)
{
cout << " is palindrome ";
}
else
cout << " is not palindrome ";
//cout << " " << obj2.isPalindrome();
cout << endl;
return 0;
}
/*
output:
Object 1:
String: madam
Object 2:
String: anil
After reversing:
String: lina
String: lina
is not palindrome
*/

More Related Content

Similar to Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf

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
Abdulrahman890100
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
jyothimuppasani1
 
String searching
String searchingString searching
String searching
Russell Childs
 
Overloading
OverloadingOverloading
Overloading
poonamchopra7975
 
C++ Pointers with Examples.docx
C++ Pointers with Examples.docxC++ Pointers with Examples.docx
C++ Pointers with Examples.docx
JoeyDelaCruz22
 
String .h
String .hString .h
String .h
Nishank Magoo
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
mohdjakirfb
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
Warui Maina
 
Link list
Link listLink list
Link list
Malainine Zaid
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
SyedHaroonShah4
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
GC University Faisalabad
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx
gertrudebellgrove
 
Strings
StringsStrings
Strings
Imad Ali
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
Aleš Najmann
 
Pointers
PointersPointers
Pointers
PreethyJemima
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
piyush Kumar Sharma
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
SURBHI SAROHA
 

Similar to Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf (20)

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
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
String searching
String searchingString searching
String searching
 
Overloading
OverloadingOverloading
Overloading
 
C++ Pointers with Examples.docx
C++ Pointers with Examples.docxC++ Pointers with Examples.docx
C++ Pointers with Examples.docx
 
String .h
String .hString .h
String .h
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
Link list
Link listLink list
Link list
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx
 
Strings
StringsStrings
Strings
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 
Pointers
PointersPointers
Pointers
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 

More from arjunhassan8

Explain how substances get across membranes and into the cell.Sol.pdf
Explain how substances get across membranes and into the cell.Sol.pdfExplain how substances get across membranes and into the cell.Sol.pdf
Explain how substances get across membranes and into the cell.Sol.pdf
arjunhassan8
 
Does yeast have a post translation pathway for protein synthesisIf .pdf
Does yeast have a post translation pathway for protein synthesisIf .pdfDoes yeast have a post translation pathway for protein synthesisIf .pdf
Does yeast have a post translation pathway for protein synthesisIf .pdf
arjunhassan8
 
Determine whether the following statements about human ABO Wood group.pdf
Determine whether the following statements about human ABO Wood group.pdfDetermine whether the following statements about human ABO Wood group.pdf
Determine whether the following statements about human ABO Wood group.pdf
arjunhassan8
 
Describe a similarity transformation that maps trapezoid WXYZ to tr.pdf
Describe a similarity transformation that maps trapezoid WXYZ to tr.pdfDescribe a similarity transformation that maps trapezoid WXYZ to tr.pdf
Describe a similarity transformation that maps trapezoid WXYZ to tr.pdf
arjunhassan8
 
blackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdf
blackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdfblackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdf
blackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdf
arjunhassan8
 
Bitcoin as an Ethical Dilemma closing case (Question below article).pdf
Bitcoin as an Ethical Dilemma closing case (Question below article).pdfBitcoin as an Ethical Dilemma closing case (Question below article).pdf
Bitcoin as an Ethical Dilemma closing case (Question below article).pdf
arjunhassan8
 
2. This seasons flu virus is spreading based on a logistic functio.pdf
2. This seasons flu virus is spreading based on a logistic functio.pdf2. This seasons flu virus is spreading based on a logistic functio.pdf
2. This seasons flu virus is spreading based on a logistic functio.pdf
arjunhassan8
 
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
^^^Q2. Discuss about Header Node    And also write a program fo.pdf^^^Q2. Discuss about Header Node    And also write a program fo.pdf
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
arjunhassan8
 
Write the code segments to create a monitor that has the same behavi.pdf
Write the code segments to create a monitor that has the same behavi.pdfWrite the code segments to create a monitor that has the same behavi.pdf
Write the code segments to create a monitor that has the same behavi.pdf
arjunhassan8
 
Which of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdfWhich of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdf
arjunhassan8
 
Which elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdfWhich elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdf
arjunhassan8
 
What domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdfWhat domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdf
arjunhassan8
 
This problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdfThis problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdf
arjunhassan8
 
The _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdfThe _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdf
arjunhassan8
 
The main difference between passive and active transport is the spec.pdf
The main difference between passive and active transport is  the spec.pdfThe main difference between passive and active transport is  the spec.pdf
The main difference between passive and active transport is the spec.pdf
arjunhassan8
 
The opposite movement of supination is ___. Pronation flexion exte.pdf
The opposite movement of supination is ___.  Pronation  flexion  exte.pdfThe opposite movement of supination is ___.  Pronation  flexion  exte.pdf
The opposite movement of supination is ___. Pronation flexion exte.pdf
arjunhassan8
 
The latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdfThe latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdf
arjunhassan8
 
The following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdfThe following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdf
arjunhassan8
 
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdfA female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
arjunhassan8
 
So I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdfSo I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdf
arjunhassan8
 

More from arjunhassan8 (20)

Explain how substances get across membranes and into the cell.Sol.pdf
Explain how substances get across membranes and into the cell.Sol.pdfExplain how substances get across membranes and into the cell.Sol.pdf
Explain how substances get across membranes and into the cell.Sol.pdf
 
Does yeast have a post translation pathway for protein synthesisIf .pdf
Does yeast have a post translation pathway for protein synthesisIf .pdfDoes yeast have a post translation pathway for protein synthesisIf .pdf
Does yeast have a post translation pathway for protein synthesisIf .pdf
 
Determine whether the following statements about human ABO Wood group.pdf
Determine whether the following statements about human ABO Wood group.pdfDetermine whether the following statements about human ABO Wood group.pdf
Determine whether the following statements about human ABO Wood group.pdf
 
Describe a similarity transformation that maps trapezoid WXYZ to tr.pdf
Describe a similarity transformation that maps trapezoid WXYZ to tr.pdfDescribe a similarity transformation that maps trapezoid WXYZ to tr.pdf
Describe a similarity transformation that maps trapezoid WXYZ to tr.pdf
 
blackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdf
blackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdfblackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdf
blackboard.ecu edu Take Test Exam ll-Blou2300601201730 he map above .pdf
 
Bitcoin as an Ethical Dilemma closing case (Question below article).pdf
Bitcoin as an Ethical Dilemma closing case (Question below article).pdfBitcoin as an Ethical Dilemma closing case (Question below article).pdf
Bitcoin as an Ethical Dilemma closing case (Question below article).pdf
 
2. This seasons flu virus is spreading based on a logistic functio.pdf
2. This seasons flu virus is spreading based on a logistic functio.pdf2. This seasons flu virus is spreading based on a logistic functio.pdf
2. This seasons flu virus is spreading based on a logistic functio.pdf
 
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
^^^Q2. Discuss about Header Node    And also write a program fo.pdf^^^Q2. Discuss about Header Node    And also write a program fo.pdf
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
 
Write the code segments to create a monitor that has the same behavi.pdf
Write the code segments to create a monitor that has the same behavi.pdfWrite the code segments to create a monitor that has the same behavi.pdf
Write the code segments to create a monitor that has the same behavi.pdf
 
Which of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdfWhich of the following is NOT a rationale for using mRNA intermed.pdf
Which of the following is NOT a rationale for using mRNA intermed.pdf
 
Which elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdfWhich elements are in series and which are in parallel in Figure P1.3.pdf
Which elements are in series and which are in parallel in Figure P1.3.pdf
 
What domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdfWhat domain is horizontal gene transfer most common within Multiple .pdf
What domain is horizontal gene transfer most common within Multiple .pdf
 
This problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdfThis problem is based on the B92 method of quantum key distri.pdf
This problem is based on the B92 method of quantum key distri.pdf
 
The _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdfThe _ operator can be used to determine a variable address The variab.pdf
The _ operator can be used to determine a variable address The variab.pdf
 
The main difference between passive and active transport is the spec.pdf
The main difference between passive and active transport is  the spec.pdfThe main difference between passive and active transport is  the spec.pdf
The main difference between passive and active transport is the spec.pdf
 
The opposite movement of supination is ___. Pronation flexion exte.pdf
The opposite movement of supination is ___.  Pronation  flexion  exte.pdfThe opposite movement of supination is ___.  Pronation  flexion  exte.pdf
The opposite movement of supination is ___. Pronation flexion exte.pdf
 
The latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdfThe latter or final stages of an RNA based heriditary world were lik.pdf
The latter or final stages of an RNA based heriditary world were lik.pdf
 
The following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdfThe following table is a summary of randomly chosen student evaluati.pdf
The following table is a summary of randomly chosen student evaluati.pdf
 
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdfA female carrier of Tay-Sachs wants to have a child with a male carri.pdf
A female carrier of Tay-Sachs wants to have a child with a male carri.pdf
 
So I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdfSo I dont understand explicit equations. Whats the formula and how.pdf
So I dont understand explicit equations. Whats the formula and how.pdf
 

Recently uploaded

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 

Recently uploaded (20)

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 

Can anyone fix this code, I use Visual StudiosThe Errors im getti.pdf

  • 1. Can anyone fix this code, I use Visual Studios: The Errors im getting is that it is not reverseing correctly, And the line if (arr[i] == strRev[i]) gives me a error code C4700 uninitialized local variable 'strRev' used This is the program that neeeds to be created: In C++, with a myString.h, myStringImp.cpp, and main.cpp: Design and implement a class myString: -Use a dynamic array of char to store the characters of myString. -Use an int to keep track of the length of myString. -Provide a parameterized constructor that takes an initial string, a default constructor, destructor, assignment operator, and copy constructor. All need to correctly handle the dynamic array. -Also provide these member functions: --length() //the length of myString --isEqual() //if it is equal to another myString --print() //output to a terminal cout or outFile --reverse() //reverse the order of characters in myString --isPalindrome() //if myString reads the same after being reversed Here is the code that is broken: C++ Code: Header File:myString.h #ifndef MYSTRING_H_INCLUDED #define MYSTRING_H_INCLUDED #include using namespace std; //Class definition class myString { public: //Char Array pointer char *arr; //Integer to hold length int len; //Default constructor myString(); //Parameter constructor
  • 2. myString(string str); //Copy constructor myString(const myString &obj); //Overloading assignment operator void operator=(const myString &obj); //Destructor ~myString(); //Returns length int length(); //Compares two string for equality bool isEqual(myString &obj); //Printing string to console void print(); //Reversing the string void reverse(); //Check for palindrome of current string and its reverse bool isPalindrome(); }; #endif // MYSTRING_H_INCLUDED Implementation File:myString.cpp /* Implementation File */ #include #include #include "myString.h" using namespace std; //Default Constructor myString :: myString() { //Initializing length to 0 len = 0; arr = new char[0]; } //Parameter constructor myString :: myString(string str) { int i;
  • 3. //Taking length len = strlen(str.c_str()); //Allocating space arr = new char[len+1]; //Copying characters for(i=0; i arr[i] = str[i]; arr[i] = '0'; } //Copy constructor myString :: myString(const myString &obj) { //Fetching length len = obj.len; //Allocating memory arr = new char[len]; //Assigning dynamic character arrays *arr = *obj.arr; } //Assignment operator overloading void myString :: operator=(const myString &obj) { //Fetching length len = obj.len; //Allocating memory arr = new char[len]; //Assigning dynamic character arrays *arr = *obj.arr; } //Destructor myString :: ~myString() { //deallocates space delete arr; } //Function that returns length of string int myString ::length()
  • 4. { return len; } //Compares two strings and returns true if they are equal else false bool myString::isEqual(myString &obj) { int i, cnt=0; //Comparing lengths if(len != (obj.len)) return false; //Comparing character by character for(i=0; i { if(arr[i] == obj.arr[i]) cnt++; } //Return value if(cnt == len) return true; else return false; } //Function that prints the string to console void myString::print() { int i; cout << " String: "; //Printing character by character for(i=0; i cout << arr[i]; cout << " "; } //Function that reverses the string void myString::reverse() { int i,j; char *tmp; tmp = new char[len];
  • 5. //Reversing the array for(i=len-1,j=0; i>=0; i--,j++) tmp[j] = arr[i]; //Reallocating string *arr = *tmp; } //Function that checks for palindrome of a string and its reverse bool myString::isPalindrome() { char *strRev; int i, cnt=0; //Creating a string object myString temp(arr); //REversing the string temp.reverse(); //Comparing character by character for(i=0; i { //Comparing char in both arrays if(arr[i] == strRev[i]) cnt++; } //If all are matched return true else false if(cnt == len) return true; else return false; } Main File: main.cpp #include #include "myString.h" using namespace std; int main() { //creating myString object 1 myString obj1("madam"); cout << " Object 1: ";
  • 6. //Printing object 1 obj1.print(); //creating myString object 2 myString obj2("anil"); cout << " Object 2: "; //Printing object 2 obj2.print(); //Reversing object 2 obj2.reverse(); //Printing object 2 after reversing cout << " After reversing: "; obj2.print(); //Checking for palindrome of object 2 with its reverse cout << " " << obj2.isPalindrome(); cout << endl; return 0; } Solution //Header File: myString.h #ifndef MYSTRING_H_INCLUDED #define MYSTRING_H_INCLUDED #include using namespace std; //Class definition class myString { public: //Char Array pointer char *arr; //Integer to hold length int len; //Default constructor myString(); //Parameter constructor
  • 7. myString(string str); //Copy constructor myString(const myString &obj); //Overloading assignment operator void operator=(const myString &obj); //Destructor ~myString(); //Returns length int length(); //Compares two string for equality bool isEqual(myString &obj); //Printing string to console void print(); //Reversing the string void reverse(); //Check for palindrome of current string and its reverse bool isPalindrome(); }; #endif // MYSTRING_H_INCLUDED //Implementation File: myString.cpp /* Implementation File */ #include #include #include #include #include #include "myString.h" using namespace std; //Default Constructor myString :: myString() { //Initializing length to 0 len = 0; arr = new char[0];
  • 8. } //Parameter constructor myString :: myString(string str) { int i; //Taking length len = strlen(str.c_str()); //Allocating space arr = new char[len+1]; //Copying characters for(i=0; i < len+1; i++) arr[i] = str[i]; arr[i] = '0'; } //Copy constructor myString :: myString(const myString &obj) { //Fetching length len = obj.len; //Allocating memory arr = new char[len]; //Assigning dynamic character arrays *arr = *obj.arr; } //Assignment operator overloading void myString :: operator=(const myString &obj) { //Fetching length len = obj.len; //Allocating memory arr = new char[len]; //Assigning dynamic character arrays *arr = *obj.arr; } //Destructor myString :: ~myString()
  • 9. { //deallocates space delete arr; } //Function that returns length of string int myString ::length() { return len; } //Compares two strings and returns true if they are equal else false bool myString::isEqual(myString &obj) { int i, cnt=0; //Comparing lengths if(len != (obj.len)) return false; //Comparing character by character for(i=0; i=0; i--,j++) tmp[j] = arr[i]; //Reallocating string strcpy(arr,tmp); } //Function that checks for palindrome of a string and its reverse bool myString::isPalindrome() { int i,j; int cnt=0; char *tmp; tmp = new char[len]; //Reversing the array for(i=len-1,j=0; i>=0; i--,j++) tmp[j] = arr[i]; //Comparing character by character for(i=0; i #include #include
  • 10. #include #include #include "myString.h" using namespace std; int main() { //creating myString object 1 myString obj1("madam"); cout << " Object 1: "; //Printing object 1 obj1.print(); //creating myString object 2 myString obj2("anil"); cout << " Object 2: "; //Printing object 2 obj2.print(); //Reversing object 2 obj2.reverse(); //Printing object 2 after reversing cout << " After reversing: "; obj2.print(); //Checking for palindrome of object 2 with its reverse cout << " "; obj2.print(); if(obj2.isPalindrome() == true) { cout << " is palindrome "; } else cout << " is not palindrome "; //cout << " " << obj2.isPalindrome(); cout << endl; return 0; } /* output:
  • 11. Object 1: String: madam Object 2: String: anil After reversing: String: lina String: lina is not palindrome */