一道C++语言的题目第一道:为了使下面的程序运行,请完成相关的类. #include"point.h
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/15 12:35:13
一道C++语言的题目
第一道:
为了使下面的程序运行,请完成相关的类.
#include"point.h"
int main()
{
Point p1,p2(3,3),p3(8,8),p4,p5,p6;
cout << "p1:" <<p1 << endl;
cout << "p2:" <<p2 << endl;
cout << "p3:" <<p3 << endl << endl;
p1.setX(10);
cout << "change p1:"<< p1 << endl << endl;
cout<< "Input x and y :";
cin >> p4;
cout << "p4:" <<p4 << endl << endl;
p5 = 5 + p2;
cout << "p5 = 5 + p2"<< endl;
cout << "p5:" <<p5 << endl ;
cout << "p2:" <<p2 << endl << endl;
if(p5 == p3)
cout <<"p5==p3" << endl << endl;
else
cout <<"p5!=p3" << endl << endl;
p6 = p3++;
cout << "p6 = p3++"<< endl;
cout << "p3:" <<p3 << endl ;
cout << "p6:" <<p6 << endl << endl;
p6 = ++p3;
cout << "p6 = ++p3"<< endl;
cout << "p3:" <<p3 << endl ;
cout << "p6:" <<p6 << endl << endl;
cout << endl;
system("pause");
return 0;
}
第一道:
为了使下面的程序运行,请完成相关的类.
#include"point.h"
int main()
{
Point p1,p2(3,3),p3(8,8),p4,p5,p6;
cout << "p1:" <<p1 << endl;
cout << "p2:" <<p2 << endl;
cout << "p3:" <<p3 << endl << endl;
p1.setX(10);
cout << "change p1:"<< p1 << endl << endl;
cout<< "Input x and y :";
cin >> p4;
cout << "p4:" <<p4 << endl << endl;
p5 = 5 + p2;
cout << "p5 = 5 + p2"<< endl;
cout << "p5:" <<p5 << endl ;
cout << "p2:" <<p2 << endl << endl;
if(p5 == p3)
cout <<"p5==p3" << endl << endl;
else
cout <<"p5!=p3" << endl << endl;
p6 = p3++;
cout << "p6 = p3++"<< endl;
cout << "p3:" <<p3 << endl ;
cout << "p6:" <<p6 << endl << endl;
p6 = ++p3;
cout << "p6 = ++p3"<< endl;
cout << "p3:" <<p3 << endl ;
cout << "p6:" <<p6 << endl << endl;
cout << endl;
system("pause");
return 0;
}
#include <iostream>
#include <cstdlib>
using namespace std;
class Point{
public:
explicit Point(int x = 0) : m_x(x), m_y(x) {}
Point(int x , int y) : m_x(x),m_y(y) {}
Point( const Point& rhs) : m_x(rhs.m_x),m_y(rhs.m_y) {}
~Point() {}
friend std::ostream& operator<<( std::ostream& ost, const Point& rhs)
{
ost << "( " << rhs.m_x << " , " << rhs.m_y << " )";
return ost;
}
friend std::istream& operator>>( std::istream& ist, Point& rhs)
{
ist >> rhs.m_x;
ist >> rhs.m_y;
return ist;
}
Point& operator++()
{
++m_x;
++m_y;
return *this;
}
// for point++
const Point operator++(int)
{
Point tmp(m_x,m_y);
++m_x;
++m_y;
return tmp;
}
bool operator==(const Point& rhs)
{
return rhs.m_x == m_x && rhs.m_y == m_y;
}
Point& operator=( const Point& rhs )
{
m_x = rhs.m_x;
m_y = rhs.m_y;
return *this;
}
const Point& operator+(const Point& rhs)
{
Point tmp;
tmp.m_x = m_x + rhs.m_x;
tmp.m_y = m_y + rhs.m_y;
return tmp;
}
friend Point& operator+(int lhs, const Point& rhs)
{
Point tmp;
tmp.m_x = lhs + rhs.m_x;
tmp.m_y = lhs + rhs.m_y;
return tmp;
}
Point& operator+=(const Point& rhs)
{
m_x += rhs.m_x;
m_y += rhs.m_y;
return *this;
}
void setX(int x)
{
m_x = x;
}
void setY(int y)
{
m_y = y;
}
void set(int x, int y)
{
m_x = x;
m_y = y;
}
private:
int m_x;
int m_y;
};
#include <cstdlib>
using namespace std;
class Point{
public:
explicit Point(int x = 0) : m_x(x), m_y(x) {}
Point(int x , int y) : m_x(x),m_y(y) {}
Point( const Point& rhs) : m_x(rhs.m_x),m_y(rhs.m_y) {}
~Point() {}
friend std::ostream& operator<<( std::ostream& ost, const Point& rhs)
{
ost << "( " << rhs.m_x << " , " << rhs.m_y << " )";
return ost;
}
friend std::istream& operator>>( std::istream& ist, Point& rhs)
{
ist >> rhs.m_x;
ist >> rhs.m_y;
return ist;
}
Point& operator++()
{
++m_x;
++m_y;
return *this;
}
// for point++
const Point operator++(int)
{
Point tmp(m_x,m_y);
++m_x;
++m_y;
return tmp;
}
bool operator==(const Point& rhs)
{
return rhs.m_x == m_x && rhs.m_y == m_y;
}
Point& operator=( const Point& rhs )
{
m_x = rhs.m_x;
m_y = rhs.m_y;
return *this;
}
const Point& operator+(const Point& rhs)
{
Point tmp;
tmp.m_x = m_x + rhs.m_x;
tmp.m_y = m_y + rhs.m_y;
return tmp;
}
friend Point& operator+(int lhs, const Point& rhs)
{
Point tmp;
tmp.m_x = lhs + rhs.m_x;
tmp.m_y = lhs + rhs.m_y;
return tmp;
}
Point& operator+=(const Point& rhs)
{
m_x += rhs.m_x;
m_y += rhs.m_y;
return *this;
}
void setX(int x)
{
m_x = x;
}
void setY(int y)
{
m_y = y;
}
void set(int x, int y)
{
m_x = x;
m_y = y;
}
private:
int m_x;
int m_y;
};
一道C++语言的题目第一道:为了使下面的程序运行,请完成相关的类. #include"point.h
关于c语言的,下面这个程序哪错了?#include "stdio.h" #include "s
求程序的运算结果#include ” stdio.h"
问一道C语言的程序题,
帮忙编写一道c语言的程序
一道困惑的C语言程序选择题!
C语言函数求面积#include "stdio.h"#define p 
急求解C语言的一道题#include "stdio.h" void main() {char a,b,c; scanf(
求解析下面的程序#include "stdafx.h"#include "iostream"#include "stri
1.程序填空下面程序的功能为:计算1~100之间的偶数之和,完成以下的程序并运行出正确的结果.# include voi
一道C语言题目,程序:求一组数中大于平均值的数的个数.
一道C语言题目.编写一个模拟两个人投掷骰子,比大小的的程序.