Question
FIVE quick C++ related questions. All the files are located below if you scroll down. Please answer all for positive rate. #26 - Problem8.cpp #27
FIVE quick C++ related questions. All the files are located below if you scroll down. Please answer all for positive rate.
#26 - Problem8.cpp
#27 - Problem 11.cpp
#28 - Problem15.cpp
#29 - Problem16.cpp
#30 - ProblemX1.cpp
//------------------------------------------------------------
// Problem #8
// Problem8.cpp
//------------------------------------------------------------
#include
#include
#include
using namespace std;
//------------------------------------------------------------
int main()
//------------------------------------------------------------
{
int *xp = new int;
cout
cout
// Error diagnosed by Dev-C++ 4.9.9.3: cast from 'int*' to 'char' loses precision
// cout
// Error diagnosed by Dev-C++ 4.9.9.3: cast from 'int*' to 'short int' loses precision
// cout
cout
cout
cout
system("PAUSE");
return( 0 );
}
//------------------------------------------------------------
// Problem #11
// Problem11.cpp
//------------------------------------------------------------
#include
#include
#include
#include
using namespace std;
//------------------------------------------------------------
int main()
//------------------------------------------------------------
{
char s[80+1];
cout
while ( cin.getline(s,80) )
{
cout
cout
}
system("PAUSE");
return( 0 );
}
//-------------------------------------------------------
// Problem #15
// Problem15.cpp
//-------------------------------------------------------
#include
#include
#include
using namespace std;
//-------------------------------------------------------
ostream &COMMA(ostream &OUT)
//-------------------------------------------------------
{
return( OUT
}
//-------------------------------------------------------
class POINT
//-------------------------------------------------------
{
/*
*/
protected:
int x;
int y;
public:
POINT(int x = 0,int y = 0): y(y),x(x) {}
//friend:
friend ostream &operator
friend istream &operator>>(istream & IN,POINT &point);
};
//-------------------------------------------------------
//friend
ostream &operator
//-------------------------------------------------------
{
OUT
return( OUT );
}
//-------------------------------------------------------
//friend
istream &operator>>(istream & IN,POINT &point)
//-------------------------------------------------------
{
char c;
IN.ignore(80,'(');
IN >> point.x;
while ( IN.peek() == ' ' )
IN.ignore();
IN >> c;
if ( c != ',' ) IN.putback(c);
IN >> point.y;
IN.ignore(80,')');
IN.ignore(80,' ');
return( IN );
}
//-------------------------------------------------------
int main()
//-------------------------------------------------------
{
POINT point;
cout
while ( cin >> point )
{
cout
cout
}
cout
system("PAUSE");
return( 0 );
}
//-------------------------------------------------------
//Problem #16
// Problem16.cpp
//-------------------------------------------------------
#include
#include
#include
using namespace std;
//-------------------------------------------------------
class COMPLEX
//-------------------------------------------------------
{
/*
| [ (( + | - )) ]
| [ (( + | - )) ]
*/
protected:
double real;
double imaginary;
public:
COMPLEX(double real = 0.0,double imaginary = 0.0): real(real),imaginary(imaginary) {}
//friend:
friend ostream &operator
{
/*
4 different possible forms of output
0.0 (real == 0.0 and imaginary == 0.0)
S#.# (real != 0.0 and imaginary == 0.0)
S#.#i (real == 0.0 and imaginary != 0.0)
S#.#S#.#i (real != 0.0 and imaginary != 0.0)
*/
if ( complex.real == 0.0 && complex.imaginary == 0.0 )
OUT
else if ( complex.real != 0.0 && complex.imaginary == 0.0 )
OUT
else if ( complex.real == 0.0 && complex.imaginary != 0.0 )
OUT
else if ( complex.real != 0.0 && complex.imaginary != 0.0 )
OUT
return( OUT );
}
friend istream &operator>>(istream & IN,COMPLEX &complex);
};
//-------------------------------------------------------
//friend
istream &operator>>(istream & IN,COMPLEX &complex)
//-------------------------------------------------------
{
/*
3 different possible forms of output
S#.# (real != 0.0 and imaginary == 0.0)
S#.#i (real == 0.0 and imaginary != 0.0)
S#.#S#.#i (real != 0.0 and imaginary != 0.0)
*/
double x;
IN >> x;
// S#.#S#.#i (real != 0.0 and imaginary != 0.0)
if ( (IN.peek() == '+') || (IN.peek() == '-') )
{
complex.real = x;
IN >> x; complex.imaginary = x;
if ( IN.peek() != 'i' )
IN.setstate(ios::failbit);
else
IN.ignore(1,'i');
}
// S#.#i (real == 0.0 and imaginary != 0.0)
else if ( IN.peek() == 'i' )
{
complex.real = 0.0;
complex.imaginary = x;
IN.ignore(1,'i');
}
// S#.# (real != 0.0 and imaginary == 0.0)
else
{
complex.real = x;
complex.imaginary = 0.0;
}
IN.ignore(1,' ');
return( IN );
}
//-------------------------------------------------------
int main()
//-------------------------------------------------------
{
COMPLEX complex;
cout
while ( cin >> complex )
{
cout
cout
}
if ( cin.fail() ) cout
cout
cout
cout
cout
system("PAUSE");
return( 0 );
}
//------------------------------------------------------------
// X1
// ProblemX1.cpp
//------------------------------------------------------------
#include
#include
#include
#include
using namespace std;
//------------------------------------------------------------
istream &skipwhite1(istream &IN)
//------------------------------------------------------------
{
char c;
do
{
c = IN.get();
} while ( isspace(c) );
IN.putback(c);
return( IN );
}
//------------------------------------------------------------
istream &skipwhite2(istream &IN)
//------------------------------------------------------------
{
char c;
while ( isspace(IN.peek()) )
{
c = IN.get();
};
return( IN );
}
//------------------------------------------------------------
int main()
//------------------------------------------------------------
{
char c;
do
{
cout > skipwhite2 >> c;
cout
} while ( c != '*' );
system("PAUSE");
return( 0 );
}
26. (Problem 8) Dr. Hanna struggled to have pointers output in uppercase hexadecimal using the (slightly-modified) code repeated below, but to no avail. Help?! int *xp = new int ; cout >', defined for the COMPLEX class is fairly c mplex: Why?! 30. (Problem X1) T or F? The user-defined stream manipulators skipwhite10 and skipwhite20 are functionally-equivalentStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started