Assignment 12
Correct the syntax and logic errors
(debug) the following code. State the
output after you correct the code. Feel
free to use visual studio, pocket C++, or other favorite C++ compiler.
( 15 points )
1.
int
main() {{
void
dostuff(char a[], char b[]);
void
main(void) {
char s1[] = "SASAZAKI";
char s2[] = "HARUNA";
dostuff(s1, s2);
cout << s2 << endl;
}
void
dostuff(char a[], char b[]) {
b[3] = b[1]; b[2] = a[4]; b[0] = a[0]; }}
Correct the syntax and logic errors
(debug) the following code. State the
output after you correct the code. Feel
free to use visual studio, pocket C++, or other favorite C++ compiler.
(15 points)
2.
#include <iosteam>
using namespace::std;
Int main() { int x = 2;
int ptr = &x;
cout >> *ptr << endl;
*ptr = 4;
cout << x << " "
<< *ptr << end1; }
Correct the syntax and logic errors
(debug) the following code. State the
output after you correct the code. Feel
free to use visual studio, pocket C++, or other favorite C++ compiler.
(20 points)
3.
#include <iostream>
using namespace std;
int main()
{
int
myarray[] = { 101,111,111,121 };;
int*
myarraypointer;
myarraypointer
= &myarray;
cout
<< *(myarraypointer ++ 0);
cout
<< "..." << myarraypointer << endl;
cout
<< *(myarraypointer ++ 3) << endl;
}
(20 points)
4.
Write C++ code to create an
interface (usually found in .h header file) for a class called MyClass.
It has one private integer member variable called x , a default constructor, a value pass constructor, a function to
get a copy of x, and a function to
change x.
(20 points)
5.
Write C++ code to create the .cpp
file (implementation) for the functions and constructor for the class MyClass from the above question. Note: there is no main() function in this cpp
file.
(10 points)
6.
Write C++ code to create the .cpp
file with the main() function to use the above classes. Create a pointer variable of type Myclass by
using the new keyword, use the functions you wrote above, and delete the
pointer.
Get Free Quote!
438 Experts Online