如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<;<;,以便于电话号码的输出。请将程序补充完整。#include<;iostream>;#include<;iomanip>;#include<;string>;using namespace std;class PhoneNumber{public: void setNumber(string number){this->;number=number;}//重载流插入操作符 friend <;span style="text-decoration: underline;">; <;/span>;(ostream &output,const PhoneNumber &num) {output<;<;num.number;return output;}private: string number;};int main(){ PhoneNumber phone; phone.setNumber("8008100598"); cout<;<;"The phone number is:"<;<;phone<;<;endl; return 0;}
举一反三
- 如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补充完整。 #include<iostream> #include<iomanip> #include<string> using namespace std; class PhoneNumber{ public: void setNumber(string number){this->number=number;} friend______(ostream&output,const PhoneNumber&nuln) //重载流插入操作符 {output<<num.number;return output;} private: string number; }; int main( ){ PhoneNumber phone; phone.setNumber("8008100598"); cout<<"The phone number is:"<<phone<<endl: return 0; }
- 以下程序的输出结果是 。 #include<iostream> using namespace std; int main() { int num = 50; int& ref = num; ref = ref + 10; cout <<"num = "<<num<<endl; num = num + 40; cout <<"ref = "<<ref<<endl; return 0; }
- (6-9)请阅读程序,写出程序运行结果。 class Phone{ private String name; private int price; public Phone(String name, int price) { this.name = name; this.price = price; } public String toString() { return ""+this.price; } } public class PhoneDemo { public static void main(String[] args) { StringBuffer sb=new StringBuffer(); Phone [] list=new Phone[3]; list[0]=new Phone("华为",3000); list[1]=new Phone("小米8",4000); list[2]=new Phone("vivo R10",2300); for(Phone p:list) sb.append(p); System.out.println(sb.toString()); } }
- 以下程序的输出结果是 。#include<;iostream>;#include<;iomanip>;using namespace std;void main(){ int i; for (i=1;i>;=0;) cout<;<;i--;}
- 9) Is this your cell phone number? A: Is B: this C: cell phone D: number