求大神帮我ps搞笑图解答

&& 查看话题
求大神帮忙解题啊!!!
必答题 (80分)
1.如何设置当前目录和搜索路径,在当前目录上的文件和在搜索路径上的文件有何区别?(2)
当前目录可以在当前目录浏览器窗口左上方的输入栏中设置,搜索路径可以通过选择操作桌面的file菜单中的Set Path菜单项来完成。在没有特别说明的情况下,只有当前目录和搜索路径上的函数和文件能够被MATLAB运行和调用,如果在当前目录上有与搜索路径上相同文件名的文件时则优先执行当前目录上的文件,如果没有特别说明,数据文件将存储在当前目录上。
2.创建符号变量和符号表达式有哪几种方法?(4)
sym&&创建单个符号变量,syms&&多个符号变量。在创建符号表达式之前,必须把符号表达式所包含的全部符号变量都创建完毕。
3.GUIDE提供哪些常用的控件工具,各有什么功能 ?(5分)
  答:在GUI开发环境中提供了下列五个方便的工具:
   (1)布局编辑器(Layout Editor)—在图形窗口中创建及布置图形对象
   (2)几何排列工具(Alignment Tool)—调整各对象之间的相互几何关系和位置
   (3)属性编辑器(Property Inspector)—查询并设置对象的属性值
   (4)对象浏览器(Object Browser)—获得当前MATLAB窗口中图形对象句柄的分级排列
   (5)菜单编辑器(Menu Editor)—建立和编辑主菜单和图形对象的鼠标右键菜单
4.&&建立不同数据类型的变量:包括双精度的数值型(numeric)、符号型(sym)、结构体(structure)、单元型(cell)、字符串型(char),函数句柄(function handle)、逻辑型(logical),并且采用whos列出各变量名,变量的数组维数,占用字节数,变量的类别。(4分)
5. 求矩阵的秩,迹,特征值和特征向量,并且对矩阵进行LU分解、QR分解及Chollesky分解(3分)。
6. 执行矩阵A和B
下列的运算:A+5*cos(B)、A.*B、 A*B、A./B、B.\A、A/B, B\A,分别解释数组运算和矩阵运算的区别。(4分)
7. 求半径为r的圆的面积和周长,分别采用脚本文件和函数文件进行编写, r值由input指令从键盘给出,数据的输出采用disp指令;并且说明脚本式文件和函数文件的特点。(5分)
8.&&级数求和:
(1) 分别用 for和while循环结构编写程序求和,并且说明for和while区别;(2) 分别采用sum和symsum求和。(5分)
9.&&表1给出x0,y0的一组数据,
x0& & & & 0& & & & 0.1 & & & & 0.2& & & & 0.3& & & & 0.4& & & & 0.5& & & & 0.6& & & & 0.7& & & & 0.8& & & & 0.9& & & & 1.0
y0& & & & -0.4470& & & & 1.9780& & & & 3.1100& & & & 5.2500& & & & 5.0200& & & & 4.6600& & & & 4.0100& & & & 4.5800& & & & 3.4500& & & & 5.3500& & & & 9.2200
(1) 分别采用3阶和11阶多项式拟合表1数据,并且分析是不是阶数越高拟合效果越好;
  (2) 根据已知表1数据组,采用3次样条插值求解x=0:0.25:1的y值;
(3) 图示原始数据、3阶和11阶多项式拟合以及插值结果在一个图中,并标注坐标轴和图例;
  (4)说明插值和拟合的区别。(8分)
采用左除和逆乘法求解两个方程组的解;并解释求解这两个方程的区别(5分)
11. 求解多项式的根,分别采用
(1)多项式求根命令roots;
(2)数值求零命令fzero ;
(3)符号运算命令solve,并将符号变量结果转化为数值解;(5分)
12. 已知y= x.^3-4*exp(x)-sin(x)/0.002,采用符号(diff)和数值微分(diff)和多项式拟合求导(polyfit,polyder),计算函数y在区间中的导数,并且图示这三种方法。(5分)
13. 求方程组的根,分别采用数值运算fsolve和符号运算solve,数值运算的初始值为x0 = ,要求显示符号运算得到结构体的每个元素的具体数值. (5分)
14. 符号矩阵
  (1) 简化符号矩阵然后求行列式、逆矩阵和秩;
  (3)(10分)
15. 椭圆的隐式方程为: ,它的参数方程可以表达为:x=a*cos()&&y=b*sin(),其中a=5,b=3;请用subplot在三个子图区域用不同的方法绘制椭圆曲线,要求为每幅子图形加上标题title和坐标轴标注,其中(1)采用ezplot分别绘制椭圆隐式和参数方程在两个子图区域;(2)当a值由1变化到5时,采用plot绘制5条椭圆曲线在另一个子图区域中,t在范围,使用linspace命令取椭圆100个点,使用legend命令来标明每一条对应的a值曲线的图例。(10分)
二、选答题(必须选4道题,每题5分,总计20分)
1. 符号运算
(1) 分解因式
(2) 化简表达式
(3) 求极限
2. 积分运算
(1)定积分运算:分别采用数值和符号运算
(2) 不定积分运算
已知微分方程采用数值运算ode和符号运算dsolve求解。
绘制(x和y的取值范围均为-2到2)图形,要求采用建立子窗口的方法在同一个图形窗口中绘制出网格图、带等高线的网格图、曲面图和带渲染效果(shading interp)的曲面图,并且每幅子图形加上标题title。
采用GUIDE工具设计椭圆(x=a*cos(t)&&y=b*sin(t))的用户界面, a和b值由编辑框输入,实现在坐标轴上显示椭圆曲线的目的。要求设计一个带有两个编辑框、一个坐标轴、一个按钮和相应的静态文本的图形用户界面,当用鼠标点击按钮时,在坐标轴内画出不同a和b值的椭圆曲线。
6. 初始状态为x=0.06的二阶微分方程,其中u(t)是单位阶跃函数(step),采用simulink建立系统仿真,并用scope模块观察结果。
没人帮忙吗???? :cat30::cat9::cat3::cat1::cat44:
var cpro_id = 'u1216994';
欢迎监督和反馈:本帖内容由
提供,小木虫仅提供交流平台,不对该内容负责。欢迎协助我们监督管理,共同维护互联网健康,如果您对该内容有异议,请立即发邮件到
联系通知管理员,也可以通过QQ周知,我们的QQ号为:8835100
我们保证在1个工作日内给予处理和答复,谢谢您的监督。
小木虫,学术科研第一站,为中国学术科研研究提供免费动力
广告投放请联系QQ: &
违规贴举报删除请联系邮箱: 或者 QQ:8835100
Copyright &
eMuch.net, All Rights Reserved. 小木虫 版权所有求大神解答_电脑吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:887,871贴子:
求大神解答收藏
我新电脑怎么老死机
配置如下14:36 CPU:
AMD Athlon(速龙) X4 740 Quad Core Processor主板:
技嘉 F2A55M-DS2 (AMD A55/A60M (Hudson-D2/M2))内存:
4 GBytes显卡:
NVIDIA(英伟达) GeForce GT 630硬盘:
WDC WD5000AAKX-00U6AA0显示器:
冠捷 E2251Fw网卡:
瑞昱 Semiconductor RTL PCI-E Gigabit Ethernet NIC声卡:
AMD Hudson-2/3/4 - High Definition Audio 控制器处理器信息 处理器:
AMD Athlon(tm) X4 740 Quad Core Processor运行速度:
3200.0 MHz核心/线程:
四核, 四线程核心代号:
Piledriver/Trinity功耗:
65.1 W插座:
FM2 (PGA)一级缓存:
指令: 2 x 64 KBytes, Data: 4 x 16 KBytes二级缓存:
集成: 2 x 2 MBytes三级缓存:
MMX SSE SSE-2 SSE-3 SSSE-3 SSE4A SSE4.1 SSE4.2 AVX x86-64主板信息 主板厂商:
技嘉主板型号:
技嘉 F2A55M-DS2芯片组:
AMD A55/A60M (Hudson-D2/M2)主板插槽:
1xPCI Express x1, 1xPCI Express x8, 2xPCI Express x16USB支持:
v2.0PCI-E支持:
v2.0BIOS版本:
F6BIOS日期:
06/26/2013内存信息(总计:4 GBytes) 内存大小:
4096 MB内存类型:
DDR3 SDRAM制造商:
金邦制造日期:
1年第周显卡信息 显卡芯片:
NVIDIA(英伟达) GeForce GT 630显存大小:
2048 MB of DDR3 SDRAM显卡型号:
NVIDIA(英伟达) GeForce GT 630 (p1071)显卡BIOS版本:
70.08.AD.00.01频率:
50.6 MHz显示器信息 显示器:
冠捷 E2251Fw生产日期:
2013年第周信号输入方式:
Digital屏幕水平尺寸:
48 cm屏幕垂直尺寸:
27 cm屏幕对角尺寸:
22英寸存储信息 存储器1:控制器:
Serial ATA 6Gb/s型号:
WDC WD5000AAKX-00U6AA0容量:
476,940 MB (500 GB)缓存:
16384 KBNCQ功能:
支持, Max. Depth: 32S.M.A.R.T.:
存在, Active48bit LBA:
支持, Active 存储器2:型号:
明基 DVDROM DD18SA
2网卡信息 硬件名称:
瑞昱 Semiconductor RTL PCI-E Gigabit Ethernet NICMAC地址:
94-DE-80-D0-6E-71最大带宽:
1000 Mbps声卡信息 声卡1:解码器:
AMD Hudson-2/3/4 - High Definition Audio 控制器 声卡2:解码器:
NVIDIA(英伟达) GF108 - High Definition Audio Controller硬件名称:
NVIDIA(英伟达) HDMI电池信息USB设备 厂商:
AVEO Technology Corp.设备名称:
USB2.0 CameraUSB版本:
2.00驱动描述:
USB Composite Device驱动描述:
USB Composite Device
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或&& 查看话题
求大神帮忙解答!
困扰了蛮久了....求大神帮忙解答程序错在哪里....疑问都在程序旁边注释出来了。
新手贴,没什么金币,抱歉....今后努力赚金币。
非常感谢.....:arm:
源程序如下:
#include&iostream&
class Port
& & & & char*
& & & & Port(const char* br=&none&, const char* st=&none&, int b=0);
& & & & Port(const Port& p);
& & & & virtual ~Port() {delete&&}
& & & & Port& operator =(const Port& p);
& & & & Port& operator+=(int b);
& & & & Port& operator-=(int b);
& & & & int BottleCount() const {}
& & & & virtual void Show()
& & & & friend std::ostream& operator&& (std::ostream& os, const Port& p);
class VintagePort: public Port
& & & & char*
& & & & VintagePort();
& & & & VintagePort(const char* br, int b, const char* nn, int y);
& & & & VintagePort(const VintagePort& vp);
& & & & ~VintagePort() {delete&&}
& & & & VintagePort& operator= (const VintagePort& vp);
& & & & virtual void Show()
& & & & friend std::ostream& operator&& (std::ostream& os, const VintagePort& vp);
//实现文件
#include&iostream&
#include&cstring&
#include&Port.h&
Port::Port(const char* br, const char* st, int b)
& &strcpy(brand, br);
& &strncpy(style, st, 20);
& &bottles=b;
Port::Port(const Port& p)
& &strcpy(brand, p.brand);
& &strncpy(style, p.style, 20);
& &bottles=p.
Port& Port::operator = (const Port& p)
& &if (this==&p)
& & & && & return *
& &delete&&
& &strcpy(brand, p.brand);
& &strncpy(style, p.style, 20);
& &bottles=p.
& &return *
Port& Port::operator += (int b)
& &bottles+=b;
& &return *
Port& Port::operator -=(int b)
& &if (b&=bottles)
& & & && & bottles-=b;
& & & && & std::cout&& &You can't take more bottles than we have!\n&
& & & && && && && & && &Operation cancelled!\n&;
& &return *
void Port::Show ()const
& & & & std::cout&& &Brand: &&& brand
& & & & & & & && && &&& &\nKind: &&& style
& & & & & & & & & & & &&&&& &\nBottles: &&& bottles
& & & & & & & & & & & &&&&&std::
std::ostream& operator&& (std::ostream& os, const Port& p)
& &os && p.brand&&&& &, & && p.style && &, & && p.
VintagePort::VintagePort()
& &nickname=
& &strcpy(nickname, &none&);
& &year=0;
VintagePort::VintagePort(const char* br, int b, const char* nn, int y)
:Port(br, &vintage&, b)
& &nickname=
& &strcpy(nickname, nn) ;
& &year=y;
VintagePort::VintagePort(const VintagePort& vp)
& &nickname=
& &strcpy(nickname, vp.nickname);
& &year=vp.
VintagePort& VintagePort::operator = (const VintagePort& vp)
& &Port::operator = (vp);
& &delete&&
& &nickname=
& &strcpy(nickname, vp.nickname);
& &year=vp.
& &return *
void VintagePort::Show () const
& & & & Port::Show ();
& & & & std::cout&& &Nickname: & && nickname
& & & & & & & && && &&& &\nYear: &&&&& year
& & & & & & & & & & & &&&&& std::
std::ostream& operator&& (std::ostream& os, const VintagePort& vp)
& &os && (const Port&)& && && &
& &os && &, & && vp.nickname && &, & && vp.
#include&iostream&
#include&Port.h&
int main()
& & & & using std::
& & & & using std::
& & & & using std::
& & & & Port*
& & & & pointer=&Port(&Lafite&, &tawny&, 27);
& & & & pointer=&Port(&Latour&, &ruby&, 23);
& & & & pointer=&VintagePort(&Haut-Brion&, 35, &The Noble&, 1875);
& & & & pointer=&VintagePort(&Margaux&, 56, &Old Velvet&, 1898);
& & & & for (int k=0;k&4;k++)& && & //这个不是主程序的部分,我是想用来测试,我用基类指针调用Show()函数的结果,
& & & & & & & && && && && && && && && & //结果与我预想的不一样,我的Show()函数是虚拟的,我用基类指针(Port*)指向派类对象
& & & && & pointer-&Show ();& &&&//用pointer-&Show()的时候,应该是调用Port::Show(),这个调用是正确的,但是我的brand成员显示却出现了乱码,这个不明白是怎么回事。
& & & && & cout &&& && && && &//用pointer-&Show()的时候,应该是调用VintagePort::Show(),这个调用是错的,结果调用的是Port::Show(),而且与上面一样brand成员显示却出现了乱码。
& & & & Port& b=Port(&Lafite&, &tawny&, 27);& &//我这里用基类引用指向基类对象,用引用调用的时候,就不出现乱码,所以我觉得应该问题出现在指针上
& & & & b.Show ();& && && && && && && && && &&&//但是,实在想不到是为什么?&&求解答。
& & & & cout && b &&
& & & & Port& a=VintagePort(&Margaux&, 56, &Old Velvet&, 1898);
& & a.Show();& && && && && && &//还有这里,我用基类引用指向派生对象,在调用Show()的时候,就调用的是VintagePort::Show(),是正确的。
& & & & cout && a &&& && && & //但是这里又出现了问题,我重载的cout && a,应该需要显示nickname和year的,但是却与cout && b是一样的,是我的重载出现问题了么??
& & & & int choice,i=4;
& & & & cout && &Do you want to take or save port(s)? (1 to take/2 to save/q to quit)&;
& & & & while (cin && choice)
& & & && & if (choice==1)
& & & && & {
& & & && && & int kind=0,num=0;
& & & & & & & && &cout && &Which brand do you need?(1:Lafite, 2:Latour, 3:Haut-Brion, 4:Margaux)&;
& & & & & & & && &cin &&
& & & & & & & && &cin.get();
& & & & & & & && &switch (kind)
& & & & & & & && &{
& & & & & & & && &case 1:
& & & & & & & & & & & && &{
& & & & & & & & & & & && && &cout && &How many bottles do you need?\n&;
& & & & & & & & & & & & & & & &&&cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & &&&cin &&
& & & & & & & & & & & & & & & &&&*pointer-=
& & & & & & & & & & & & & & & &&&pointer-&Show();
& & & & & & & & & & & & & & & &&&
& & & & & & & & & & & && &}
& & & & & & & && &case 2:
& & & & & & & & & & & && &{
& & & & & & & & & & & && && &cout && &How many bottles do you need?\n&;
& & & & & & & & & & & & & & & &&&cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & &&&cin &&
& & & & & & & & & & & & & & & &&&*pointer-=
& & & & & & & & & & & & & & & &&&pointer-&Show();
& & & & & & & & & & & & & & & &&&
& & & & & & & & & & & && &}
& & & & & & & && &case 3:
& & & & & & & & & & & && &{
& & & & & & & & & & & && && &cout && &How many bottles do you need?&;
& & & & & & & & & & & & & & & &&&cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & &&&cin &&
& & & & & & & & & & & & & & & &&&(Port&)*pointer-=& & //或者直接用*pointer-=因为-=的函参为Port&,可以指向VintagePort。
& & & & & & & & & & & & & & & &&&pointer-&Show();
& & & & & & & & & & & & & & & &&&
& & & & & & & & & & & && &}
& & & & & & & && &case 4:
& & & & & & & & & & & && &{
& & & & & & & & & & & && && &cout && &How many bottles do you need?&;
& & & & & & & & & & & & & & & &&&cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & &&&cin &&
& & & & & & & & & & & & & & & &&&*pointer-=
& & & & & & & & & & & & & & & &&&pointer-&Show();
& & & & & & & & & & & & & & & &&&
& & & & & & & & & & & && &}
& & & & & & & && &default: cout && &That's not a choice!\n&;
& & & & & & & && &}
& & & && & }
& & & && & else
& & & && & {
& & & & & & & && &int num=0;
& & & && && & cout && &Please enter the brand:&;& & //这里我无法进行输入。
& & & & & & & && &
& & & & & & & && &cin.getline(temp, 50);
& & & & & & & && &cin.get();
& && && & if (temp==&Lafite&)& &&&//我这里的字符串的比较应该是有问题的,不能用==判断。
& & & & & & & && &{
& & & & & & & && && &cout && &Save bottles: &;
& & & & & & & & & & & &&&cin &&
& && && && & *pointer+=
& & & & & & & & & & & &&&pointer-&Show();
& & & & & & & && &}
& & & & & & & && &else if (temp==&Latour&)
& & & & & & & && &{
& & & & & & & && && &cout && &Save bottles: &;
& & & & & & & & & & & &&&cin &&
& && && && & *pointer+=
& & & & & & & & & & & &&&pointer-&Show();&&
& & & & & & & && &}
& & & & & & & && &else if (temp==&Haut-Brion&)
& & & & & & & && &{
& & & & & & & && && &cout && &Save bottles: &;
& & & & & & & & & & & &&&cin &&
& && && && & *pointer+=
& & & & & & & & & & & &&&pointer-&Show();
& & & & & & & && &}
& & & & & & & && &else if (temp==&Margaux&)
& & & & & & & && &{
& & & & & & & && && &cout && &Save bottles: &;
& & & & & & & & & & & &&&cin &&
& && && && & *pointer+=
& & & & & & & & & & & &&&pointer-&Show();
& & & & & & & && &}
& & & & & & & && &else
& & & & & & & && &{
& & & & & & & && && &cout && &Enter the style: &;
& & & & & & & & & & & &&&char s_
& & & & & & & & & & & &&&cin.getline(s_temp, 10);
& & & & & & & & & & & &&&if (s_temp==&vintage&)& && & //这里的判断也有问题。
& & & & & & & & & & & &&&{
& & & & & & & & & & & && &&&cout && &Enter the nickname: &;
& & & & & & & & & & & & & & & & char n_
& & & & & & & & & & & & & & & & cin.getline(n_temp, 20);
& & & & & & & & & & & & & & & & cout && &Enter the year: &;
& & & & & & & & & & & & & & & & int y_
& & & & & & & & & & & & & & & & cin && y_
& & & & & & & & & & & & & & & & cout && &Enter the bottles: &;
& & & & & & & & & & & & & & & & int b_
& & & & & & & & & & & & & & & & cin && b_
& & & & & & & & & & & & & & & & pointer=&VintagePort(temp, b_temp, n_temp, y_temp);
& & & & & & & & & & & &&&}
& & & & & & & & & & & &&&else
& & & & & & & & & & & &&&{
& & & & & & & & & & & & & & & & cout && &Enter the bottles: &;
& && && && && & int b_
& & & & & & & & & & & & & & & & cin && b_
& & & & & & & & & & & && & pointer=&Port(temp, s_temp, b_temp);
& & & & & & & & & & & &&&}
& & & & & & & && &}
& & & && & }
& & & && & ++i;
& & & && & cout && &Do you want to take or save port(s)? (1 to take/2 to save/q to quit)&;
& & & & cin.get();
& & & & cout && &Do you want to see all the Port's information?(y/n) &;&&//最后还有这里,无法进行输入....
& & & & cin.get(ch);
& & & & if (ch=='y'||ch=='Y')
& & & && & for (int c=0;c&i;++c)
& & & & & & & && & cout && *pointer &&
& & cout && &Bye!\n&;
& & & & return 0;& &
里面的符号有的变成了表情....汗....
& &但是直接复制的话,应该是可以变回来的吧!?:cry: #include&iostream&
class Port
& & & & char*
& & & & Port(const char* br = &none&, const char* st = &none&, int b = 0);
& & & & Port(const Port& p);
& & & & virtual ~Port() { }
& & & & Port& operator =(const Port& p);
& & & & Port& operator+=(int b);
& & & & Port& operator-=(int b);
& & & & int BottleCount() const { }
& & & & virtual void Show()
& & & & friend std::ostream& operator&& (std ::ostream& os, const Port& p);
class VintagePort : public Port
& & & & char*
& & & & VintagePort();
& & & & VintagePort(const char* br, int b, const char* nn, int y);
& & & & VintagePort(const VintagePort& vp);
& & & & ~VintagePort() { }
& & & & VintagePort& operator= (const VintagePort& vp);
& & & & virtual void Show()
& & & & friend std::ostream& operator&& (std::ostream& os, const VintagePort& vp);
//实现文件
#include&iostream&
#include&cstring&
#include&Port.h&
Port::Port(const char* br, const char* st, int b)
& & & & brand =
& & & & strcpy(brand, br);
& & & & strncpy(style, st, 20);
& & & & bottles =
Port::Port(const Port& p)
& & & & brand =
& & & & strcpy(brand, p.brand);
& & & & strncpy(style, p.style, 20);
& & & & bottles = p.
Port& Port::operator = (const Port& p)
& & & & if (this == &p)
& & & & & & & & return *
& & & & delete&&
& & & & brand =
& & & & strcpy(brand, p.brand);
& & & & strncpy(style, p.style, 20);
& & & & bottles = p.
& & & & return *
Port& Port::operator += (int b)
& & & & bottles +=
& & & & return *
Port& Port::operator -= (int b)
& & & & if (b &= bottles)
& & & & & & & & bottles -=
& & & & else
& & & & & & & & std::cout && &You can't take more bottles than we have!\n&
& & & & & & & & && &Operation cancelled!\n&;
& & & & return *
void Port::Show()const
& & & & std::cout && &Brand: & && brand
& & & & & & & & && &\nKind: & && style
& & & & & & & & && &\nBottles: & && bottles
& & & & & & & & && std::
std::ostream& operator&& (std::ostream& os, const Port& p)
& & & & os && p.brand && &, & && p.style && &, & && p.
VintagePort::VintagePort()
& & & & nickname =
& & & & strcpy(nickname, &none&);
& & & & year = 0;
VintagePort::VintagePort(const char* br, int b, const char* nn, int y)
:Port(br, &vintage&, b)
& & & & nickname =
& & & & strcpy(nickname, nn);
& & & & year =
VintagePort::VintagePort(const VintagePort& vp)
& & & & nickname =
& & & & strcpy(nickname, vp.nickname);
& & & & year = vp.
VintagePort& VintagePort::operator = (const VintagePort& vp)
& & & & Port::operator = (vp);
& & & & delete&&
& & & & nickname =
& & & & strcpy(nickname, vp.nickname);
& & & & year = vp.
& & & & return *
void VintagePort::Show() const
& & & & Port::Show();
& & & & std::cout && &Nickname: & && nickname
& & & & & & & & && &\nYear: & && year
& & & & & & & & && std::
std::ostream& operator&& (std::ostream& os, const VintagePort& vp)
& & & & os && (const Port&)
& & & & os && &, & && vp.nickname && &, & && vp.
#include&iostream&
#include&Port.h&
int main()
& & & & using std::
& & & & using std::
& & & & using std::
& & & & Port*
& & & & //pointer = &Port(&Lafite&, &tawny&, 27);
& & & & //pointer = &Port(&Latour&, &ruby&, 23);
& & & & //pointer = &VintagePort(&Haut-Brion&, 35, &The Noble&, 1875);
& & & & //pointer = &VintagePort(&Margaux&, 56, &Old Velvet&, 1898);
& & & & Port pa = Port(&Lafite&, &tawny&, 27);
& & & & Port pb = Port(&Latour&, &ruby&, 23);
& & & & VintagePort va = VintagePort(&Haut-Brion&, 35, &The Noble&, 1875);
& & & & VintagePort vb = VintagePort(&Margaux&, 56, &Old Velvet&, 1898);
& & & & pointer = & // 只能对左值取地址,像你那样取地址是非法的,其实Port的析构函数都已经调用
& & & & pointer = &
& & & & pointer = &
& & & & pointer = &
& & & & for (int k = 0; k&4; k++)
& & & & & & & & pointer-&Show();
& & & & & & & & cout &&
& & & & //Port& b = Port(&Lafite&, &tawny&, 27);
& & & & Port prefb = Port(&Lafite&, &tawny&, 27);
& & & & Port &b =
& & & & // 或者你可以直接用Port &&b = Port(&Lafite&, &tawny&, 27);
& & & & // 或者const Port &b = Port(&Lafite&, &tawny&, 27);
& & & & // 只有常量引用和右值引用可以绑定在一个临时变量上,你看到没给你报错不代表你的写法
& & & & // 就真的没有错误,只是微软的编译器没有支持标准而已
& & & & b.Show();
& & & & cout && b &&
& & & & Port&& a = VintagePort(&Margaux&, 56, &Old Velvet&, 1898);//同上
& & & & a.Show();
& & & & cout && a &&// 没明白你这怎么重载了,operator(ostream, const Port&)直接从非const到const转换的匹配,没有任何问题
& & & & int choice, i = 4;
& & & & cout && &Do you want to take or save port(s)? (1 to take/2 to save/q to quit)&;
& & & & while (cin && choice)
& & & & & & & & if (choice == 1)
& & & & & & & & {
& & & & & & & & & & & & int kind = 0, num = 0;
& & & & & & & & & & & & cout && &Which brand do you need?(1:Lafite, 2:Latour, 3:Haut-Brion, 4:Margaux)&;
& & & & & & & & & & & & cin &&
& & & & & & & & & & & & cin.get();
& & & & & & & & & & & & switch (kind)
& & & & & & & & & & & & {
& & & & & & & & & & & & case 1:
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & && &cout && &How many bottles do you need?\n&;
& & & & & & & & & & & & & & & & & & & && &cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & & & & & && &cin &&
& & & & & & & & & & & & & & & & & & & && &*pointer -=
& & & & & & & & & & & & & & & & & & & && &pointer-&Show();
& & & & & & & & & & & & & & & & & & & && &
& & & & & & & & & & & & }
& & & & & & & & & & & & case 2:
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & && &cout && &How many bottles do you need?\n&;
& & & & & & & & & & & & & & & & & & & && &cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & & & & & && &cin &&
& & & & & & & & & & & & & & & & & & & && &*pointer -=
& & & & & & & & & & & & & & & & & & & && &pointer-&Show();
& & & & & & & & & & & & & & & & & & & && &
& & & & & & & & & & & & }
& & & & & & & & & & & & case 3:
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & && &cout && &How many bottles do you need?&;
& & & & & & & & & & & & & & & & & & & && &cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & & & & & && &cin &&
& & & & & & & & & & & & & & & & & & & && &(Port*)pointer -=& & //或者直接用*pointer-=因为-=的函参为Port&,可以指向VintagePort。
& & & & & & & & & & & & & & & & & & & && &pointer-&Show();
& & & & & & & & & & & & & & & & & & & && &
& & & & & & & & & & & & }
& & & & & & & & & & & & case 4:
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & && &cout && &How many bottles do you need?&;
& & & & & & & & & & & & & & & & & & & && &cout && &There're & && pointer-&BottleCount() && & saved.\n&;
& & & & & & & & & & & & & & & & & & & && &cin &&
& & & & & & & & & & & & & & & & & & & && &*pointer -=
& & & & & & & & & & & & & & & & & & & && &pointer-&Show();
& & & & & & & & & & & & & & & & & & & && &
& & & & & & & & & & & & }
& & & & & & & & & & & & default: cout && &That's not a choice!\n&;
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & & else
& & & & & & & & {
& & & & & & & & & & & & int num = 0;
& & & & & & & & & & & & cout && &Please enter the brand:&;// &&& & //这里我无法进行输入。
& & & & & & & & & & & &
& & & & & & & & & & & & cin.get();
& & & & & & & & & & & & cin.getline(temp, 50);// 你原始的做法是直接获取新的一行,当然得到的就是'\n',没有什么不能输入的
& & & & & & & & & & & & //cin.get();
& & & & & & & & & & & & if (strcmp(temp,&Lafite&) == 0)& &&&//我这里的字符串的比较应该是有问题的,不能用==判断。
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & cout && &Save bottles: &;
& & & & & & & & & & & & & & & & cin &&
& & & & & & & & & & & & & & & & *pointer +=
& & & & & & & & & & & & & & & & pointer-&Show();
& & & & & & & & & & & & }
& & & & & & & & & & & & else if (strcmp(temp,&Latour&) == 0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & cout && &Save bottles: &;
& & & & & & & & & & & & & & & & cin &&
& & & & & & & & & & & & & & & & *pointer +=
& & & & & & & & & & & & & & & & pointer-&Show();
& & & & & & & & & & & & }
& & & & & & & & & & & & else if ( strcmp(temp,&Haut-Brion&) == 0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & cout && &Save bottles: &;
& & & & & & & & & & & & & & & & cin &&
& & & & & & & & & & & & & & & & *pointer +=
& & & & & & & & & & & & & & & & pointer-&Show();
& & & & & & & & & & & & }
& & & & & & & & & & & & else if ( strcmp(temp,&Margaux&) == 0)
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & cout && &Save bottles: &;
& & & & & & & & & & & & & & & & cin &&
& & & & & & & & & & & & & & & & *pointer +=
& & & & & & & & & & & & & & & & pointer-&Show();
& & & & & & & & & & & & }
& & & & & & & & & & & & else
& & & & & & & & & & & & {
& & & & & & & & & & & & & & & & cout && &Enter the style: &;
& & & & & & & & & & & & & & & & char s_
& & & & & & & & & & & & & & & & cin.getline(s_temp, 10);
& & & & & & & & & & & & & & & & if ( strcmp(s_temp,&vintage&) == 0)& && & //这里的判断也有问题。
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & cout && &Enter the nickname: &;
& & & & & & & & & & & & & & & & & & & & char n_
& & & & & & & & & & & & & & & & & & & & cin.getline(n_temp, 20);
& & & & & & & & & & & & & & & & & & & & cout && &Enter the year: &;
& & & & & & & & & & & & & & & & & & & & int y_
& & & & & & & & & & & & & & & & & & & & cin && y_
& & & & & & & & & & & & & & & & & & & & cout && &Enter the bottles: &;
& & & & & & & & & & & & & & & & & & & & int b_
& & & & & & & & & & & & & & & & & & & & cin && b_
& & & & & & & & & & & & & & & & & & & & pointer =&&new VintagePort(temp, b_temp, n_temp, y_temp);//不知道你想用哪一个pointer,暂时用5,自己改
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & else
& & & & & & & & & & & & & & & & {
& & & & & & & & & & & & & & & & & & & & cout && &Enter the bottles: &;
& & & & & & & & & & & & & & & & & & & & int b_
& & & & & & & & & & & & & & & & & & & & cin && b_
& & & & & & & & & & & & & & & & & & & & pointer = new Port(temp, s_temp, b_temp);//不知道你想用哪一个pointer
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & }
& & & & & & & & }
& & & & & & & & ++i;
& & & & & & & & cout && &Do you want to take or save port(s)? (1 to take/2 to save/q to quit)&;
& & & & cin.get();
& & & & cout && &Do you want to see all the Port's information?(y/n) &;&&//最后还有这里,无法进行输入....
& & & & cin.get(ch);
& & & & if (ch == 'y' || ch == 'Y')
& & & & for (int c = 0; c&i; ++c)
& & & & & & & & cout && *pointer &&
& & & & cout && &Bye!\n&;
& & & & return 0;
} : Originally posted by 木叶清风 at
#include&iostream&
class Port
& & & & char*
& & & & Port(const char* br = &none&, const char* st = &none&, int b = 0);
& & & & Por ... 非常感谢,问题已经解决了绝大部分....
这里还有一些疑问,希望能得到解决:
1.如何发代码帖子,我的符号变成表情了,注意到您的代码外面穿了马甲:code,请问怎么做到的....我是新人,嘿嘿。
2.Port &&b = Port(&Lafite&, &tawny&, 27);& & 这里好像有错误,报错 引用无法赋值给引用.....
您说,只有常量引用和右值引用可以绑定在一个临时变量上,我写的是Port& b = Port(&Lafite&, &tawny&, 27);我把左值引用绑定在了临时变量上(请问,您说是不规范的,这里是为什么不规范?),const Port &b = Port(&Lafite&, &tawny&, 27);这个是把常量引用绑定在临时变量上,但是请问一下把右值引用绑定在临时变量上是什么例子?
3. pointer =&&new VintagePort(temp, b_temp, n_temp, y_temp);&&这里为什么要new一个VintagePort? 还是因为只能对左值进行取地址操作?如果仅仅是 Port(&Lafite&, &tawny&, 27);这里创建的是临时变量么??
4.& & & & cout && &Do you want to see all the Port's information?(y/n) &;&&//最后还是无法输入。
& & & & cin.get();//我在这里已经用这个把cin &&留下的\n给销毁了,但是下面一个读取还是不能工作。
& & & & cin.get(infor);
& & & & if (infor=='y'||infor=='Y')
& & & && & for (int c=0;c&i;++c)
& & & & & & & && & cout && *pointer &&
& & & & else
& && &&&cout && &Bye!\n&;
十分感谢。 : Originally posted by lhy at
非常感谢,问题已经解决了绝大部分....
这里还有一些疑问,希望能得到解决:
1.如何发代码帖子,我的符号变成表情了,注意到您的代码外面穿了马甲:code,请问怎么做到的....我是新人,嘿嘿。
2.Port && ... 呃...另外.....最后一个输出所有信息,我发觉似乎有问题...我用的是
&&*pointer ,这里所有的都应该调用的是&& (Port),所以我的VintagePort的信息估计会显示不完全...这里有没有办法能够解决??:P : Originally posted by lhy at
非常感谢,问题已经解决了绝大部分....
这里还有一些疑问,希望能得到解决:
1.如何发代码帖子,我的符号变成表情了,注意到您的代码外面穿了马甲:code,请问怎么做到的....我是新人,嘿嘿。
2.Port && ... 1 高级回复可以插入代码
2 右值引用需要c++11支持,编译的时候带上选项,vs都是直接编译就行了,要是没有这么高版本的编译器又不想用g++,那直接改成const Port&就行了;至于临时变量的问题我只能说好好的找本c++的书看看;
3 我只能说那确实是个临时变量,我代码里面没有写释放内存的部分,因为我不知道你到地是想用5还是多少,需要自己把这部分代码补上;
4 把quit的部分直接改成3或者其它数字,cin && choice, 你输入一个字母算什么呀;
5 把输出的部分写成虚函数,或者用RTTI查看是不是派生类,是的话进行转换再输出。 : Originally posted by 木叶清风 at
1 高级回复可以插入代码
2 右值引用需要c++11支持,编译的时候带上选项,vs都是直接编译就行了,要是没有这么高版本的编译器又不想用g++,那直接改成const Port&就行了;至于临时变量的问题我只能说 ... 嗯....我自己用程序测试了一下,这个是个临时变量,创建后马上调用了析构函数......
呃,我这里用cin && choice是想把cin的返回值当作判断条件,因为当我输入数字的时候cin返回1进入循环,输入非数字的时候就读取失败cin返回0,退出循环。& &我按着您的提示修改了程序,用break来跳出循环....程序确实是可以运行了,最后也可以进行输入了...但是我不明白用cin && choice来进行输入,为什么会影响到后面一个字符的输入,我觉得这里应该是最后一个输入读取了前方的q或者\n,所以直接判断为非y所以无法显示所有信息.....
然后,只有成员函数才可以写成虚函数,如果我这里写成虚函数了就只能有一个函参,这么写:virtual std::ostream& operator && (std::ostream & os) {os && *(ps:原来的&&没变,这里调用原来的友元)},所以我在输出的时候这么调用*pointer&& cout &&看起来蛮别扭,但是结果确实是正确的....请问,这个方法能不能改进使得用 cout && *opinter;来调用??
还有您说的RTTI自己还没有涉及到,但是我在想如果检查出是派生对象,把基类*pointer进行转换了输出,这个岂不是向下转换,理论上是不允许的,因为可能丢失数据,难道这里的可以么??
最后,我目前才学习C++不久,使用的教材是《C++ primer Plus(第五版)》,觉得还不错,即将把这本书看完,这里希望您能给点指导,想知道看完这本书后可以继续看看别的什么比较好的教材来深入学习....
非常感谢您不厌其烦的指导.... : Originally posted by lhy at
嗯....我自己用程序测试了一下,这个是个临时变量,创建后马上调用了析构函数......
呃,我这里用cin && choice是想把cin的返回值当作判断条件,因为当我输入数字的时候cin返回1进入循环,输入非数字的时候 ... 写虚函数,然后在重载的输出操作符中调用;
知道正确的类型情况下向下转换指针没有什么问题的,理论上怎么不会不允许;
好好的看&C++ Primer, 5th& 和新版的《C++ Programming Language》,看懂这两本对于语言特性来说足矣。再往后就是设计模式,专业库的使用这些提高的部分了。我还是那句话,一群人放着这两本最经典的不看,到处说不知道怎么学C++。任何语言都一样,要想学,先把经典看了再说。 : Originally posted by 木叶清风 at
写虚函数,然后在重载的输出操作符中调用;
知道正确的类型情况下向下转换指针没有什么问题的,理论上怎么不会不允许;
好好的看&C++ Primer, 5th& 和新版的《C++ Programming Language》,看懂这两本对于 ... Okay....谢谢指导...看来我滴学习方向还是对滴!&&呵呵:P
var cpro_id = 'u1216994';
欢迎监督和反馈:本帖内容由
提供,小木虫仅提供交流平台,不对该内容负责。欢迎协助我们监督管理,共同维护互联网健康,如果您对该内容有异议,请立即发邮件到
联系通知管理员,也可以通过QQ周知,我们的QQ号为:8835100
我们保证在1个工作日内给予处理和答复,谢谢您的监督。
小木虫,学术科研第一站,为中国学术科研研究提供免费动力
广告投放请联系QQ: &
违规贴举报删除请联系邮箱: 或者 QQ:8835100
Copyright &
eMuch.net, All Rights Reserved. 小木虫 版权所有

我要回帖

更多关于 求大神给个网站你懂的 的文章

 

随机推荐