精华内容
下载资源
问答
  • C++程序设计(第三版) 谭浩强 习题9.10 个人设计 ...主函数中调用display函数,display函数分别引用Time和Date两个类的对象的私有数据,输出年、月、日和时、分、秒。 代码块: #include <io...

    C++程序设计(第三版) 谭浩强 习题9.10 个人设计

    习题 9.10 将例9.13程序中的display函数不放在Time类中,而作为类外的普通函数,然后分别在Time和Date类中将display声明为友元函数。在主函数中调用display函数,display函数分别引用Time和Date两个类的对象的私有数据,输出年、月、日和时、分、秒。

    代码块:

    #include <iostream>
    using namespace std;
    class Date;
    class Time
    {
    public:
        Time(int h, int m, int s): hour(h), minute(m), sec(s){};
        friend void display(Date &, Time &);
    private:
        int hour;
        int minute;
        int sec;
    };
    class Date
    {
    public:
        Date(int m, int d, int y): month(m), day(d), year(y){};
        friend void display(Date &, Time &);
    private:
        int month;
        int day;
        int year;
    };
    void display(Date &d, Time &t)
    {
        cout<<d.month<<"/"<<d.day<<"/"<<d.year<<endl;
        cout<<t.hour<<":"<<t.minute<<":"<<t.sec<<endl;
    }
    int main()
    {
        Time t1(10, 13, 56);
        Date d1(12, 25, 2004);
        display(d1, t1);
        system("pause");
        return 0;
    }
    展开全文
  • 改为fun函数中调用change和display函数。fun函数使用对象的引用(Student &amp;)作为形参。 代码块: #include &lt;iostream&gt; using namespace std; class Student {...

    C++程序设计(第三版) 谭浩强 习题9.8 个人设计

    习题 9.8 修改第6题的程序,增加一个fun函数,改写main函数。改为在fun函数中调用change和display函数。在fun函数中使用对象的引用(Student &)作为形参。

    代码块:

    #include <iostream>
    using namespace std;
    class Student
    {
    public:
        Student(int n, float s):num(n), score(s){}
        void change(int n, float s)
        {
            num=n;
            score=s;
        }
        void display()
        {
            cout<<num<<" "<<score<<endl;
        }
    private:
        int num;
        float score;
    };
    void fun(Student &ss)
    {
        ss.display();
        ss.change(101, 80.5);
        ss.display();
    }
    int main()
    {
        Student stud(101, 78.5);
        fun(stud);
        system("pause");
        return 0;
    }
    展开全文
  • int main() { void display(const Date &,const Time &); int year,month,day; cin>>year>>month>>day; Date d1(year,month,day); int hour,minute,second; cin>>hour>>minute>>second; Time t1(hour...
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    class Time;   //不可省略
    class Date
    {
    public:
    /*	Date(int y,int m,int d)
    	{
    		year=y;
    		month=m;
    		day=d;
    	}*/
    	Date(int y,int m,int d):year(y),month(m),day(d) {}
    
    	friend void display(const Date &,const Time &);
    
    private:
        int year;
        int month;
        int day;
    
    };
    
    class Time
    {
    public:
    /*	Time(int h,int m,int s)
    	{
    		hour=h;
    		minute=m;
    		second=s;
    	}*/
    	Time(int h,int m,int s):hour(h),minute(m),second(s) {}
    
    	friend void display(const Date &,const Time &);
    
    private:
    	int hour;
    	int minute;
    	int second;
    };
    
    void display(const Date &d,const Time &t)
    {
    	cout<<d.year<<"/"<<d.month<<"/"<<d.day<<endl;
    	cout<<t.hour<<":"<<t.minute<<":"<<t.second<<endl;
    }
    
    
    int main()
    
    {
    
        void display(const Date &,const Time &);
    
        int year,month,day;
    
        cin>>year>>month>>day;
    
        Date d1(year,month,day);
    
        int hour,minute,second;
    
        cin>>hour>>minute>>second;
    
        Time t1(hour,minute,second);
    
        display(d1,t1);
    
        return 0;
    
    }

     

    展开全文
  • web页中调用客户端程序的方法

    千次阅读 2017-07-28 11:18:01
    许多人的博客可以看到有这样的小玩意 , 点击下...很显然,这是腾讯web页调用自己的QQ,那么他们是怎么做的呢? 我们先看一下腾讯给我们提供的代码:  a href ="tencent://message/?uin=88888888

    http://blog.csdn.net/aoyo/article/details/5115189

    在许多人的博客中可以看到有这样的小玩意 , 点击下就可以和博主进行对话,而且无需加博主为好友。很显然,这是腾讯在web页中的调用自己的QQ,那么他们是怎么做的呢?
    我们先看一下腾讯给我们提供的代码:
    < href ="tencent://message/?uin=88888888&Site=JooIT.com&Menu=yes" > 
    < img border ="0" SRC ='http://is.qq.com/webpresence/images/status/01_online.gif' alt ="点击这里给我发消息" > 
    </ a > 
    很显然,奥妙就在“tencent://message/?uin=215555521&Site=JooIT.com&Menu=yes”这里,那这又到底是什么原理呢?
    我们想一下,如果要打开本地的 QQ,肯定要分两步走,首先是定位到 QQ,然后是传递给它一些参数,也就是“uin=uin=88888888&Site=JooIT.com&Menu=yes ”这样的东西。 定位的话,借助注册表是最明显的方式了。可怎么把 QQ跑起来呢?要我们自己去启动一个进程么?(当然也可以,不过有更简单的何必呢),答案是否定的,Windows操作系统考虑了这一点,允许我们为自己的应用程序注册为一个协议处理者,具体参见 MSDN上的文章《Registering an Application to a URL Protocol 》。

    腾讯的Tencent://Message协议注册表如下:

    知道了原理,那么我们照葫芦画瓢的做个DemoSA实验一下:
    打开Visual Studio 2008(你也可以用其他的开发工具,Delphi,VB都可以),新建一个Windows Forms项目,在默认的Form1里添加一个Label控件(这里是为了显示传递过来的参数用的,你也可以不这么做),在窗体的Load事件里写上如下 代码:
    this.label1.Text = strArgs;//是Form1的声明为:Public的String类型变量
    为了让我们的程序支持命令行参数(winform程序默认没有命令行参数),我们再到Programs.cs里对Main()函数进行改造。
    改造后的代码如下:
    [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Form1 frm = new Form1();
                if (args.Length >0)
                {
                    frm.strArgs = args[0];
                    Application.Run(frm);
                }
                else
                {
                    Application.Run(new Form1());
                }
            }
    将项目编译。

    好了,来到最关键的步骤了,在注册表中为我们自定义的helloworld 协议建立起注册表项,从而让HelloWorld 应用程序支持此协议。将如下的注册表项加入即可, 这里为了简单起见我直接用一个.reg 文件来实现,也可以用其他方式进行:
    Windows Registry Editor Version 5.00 

    [HKEY_CLASSES_ROOT / HelloWorld]
    @ = " HelloWorld Protocol " 
    " URL Protocol " = "" 

    [HKEY_CLASSES_ROOT / HelloWorld / DefaultIcon]
    @ = " D://My Documents//Visual Studio 2005//Projects//HelloWorld//release//HelloWorld.exe,1 " 

    [HKEY_CLASSES_ROOT / HelloWorld / shell ]
    @ = "" 

    [HKEY_CLASSES_ROOT / HelloWorld / shell / open]
    @ = "" 

    [HKEY_CLASSES_ROOT / HelloWorld / shell / open / command ]
    @ = " / " D: // My Documents // Visual Studio 2005 // Projects // HelloWorld // release // HelloWorld . exe / " / " %1 /"" 

     

     

       好了,这下可以来测试 helloworld协议了,在地址栏中输入: helloworld://hello world/,怎么样,下面的画面出来了吧,

     

     
    再来到web 页面进行测试,修改上面的html 代码如下:
    < html > 
    < head ></ head > 
    < body > 
    < div > 
    < href ="helloworld://hello world" > 
    < img border ="0" SRC ='http://is.qq.com/webpresence/images/status/01_online.gif' alt ="点击这里给我发消息" > 
    </ a > 
    </ div > 
    </ body > 
    </ html > 

        若是要在web页面调用本地的winform程序,同理也是可行的。

    Windows Registry Editor Version 5.00 

    [HKEY_CLASSES_ROOT/Tencent]
    @= " TencentProtocol " 
    " URL Protocol " = " D://Program Files//Tencent//QQ//Timwp.exe " 

    [HKEY_CLASSES_ROOT/Tencent/DefaultIcon]
    @= " D://Program Files//Tencent//QQ//Timwp.exe,1 " 

    [HKEY_CLASSES_ROOT/Tencent/shell]

    [HKEY_CLASSES_ROOT/Tencent/shell/open]

    [HKEY_CLASSES_ROOT/Tencent/shell/open/command]
     @= " / " D://Program Files//Tencent//QQ//Timwp.exe/ " / "% 1 / ""

       此注册表所实现的就是当浏览器(或其它)碰到 tencent://… 时,自动调用 Timwp.exe ,并把 tencent://… 地址作为第一个参数传递给 Timwp.exe 。

     

    Registering an Application to a URL Protocol

    The About Asynchronous Pluggable Protocols article describes how to develop handlers for URL protocols. In some cases, it may be desirable to invoke another application to handle a custom protocol. To do so, register the existing application as a URL Protocol handler. Once the application has successfully launched, it can use command-line parameters to retrieve the URL that launched it. These settings apply to protocol handlers launched from within Windows Internet Explorer and from Windows Explorer using the Run... command (Windows logo key+R).

    security note Security Alert   Applications that handle URL protocols must consider how to respond to malicious data. Because handler applications can receive data from untrusted sources, the URL and other parameter values passed to the application may contain malicious data that attempts to exploit the handling application.

    This topic contains the following sections:

    Registering the Application Handling the Custom Protocol

    To register an application to handle a particular URL protocol, add a new key, along with the appropriate subkeys and values, to HKEY_CLASSES_ROOT. The root key must match the protocol scheme that is being added. For instance, to add an "alert:" protocol, add an alert key to HKEY_CLASSES_ROOT, as follows:

    HKEY_CLASSES_ROOT 
         alert 

              URL Protocol = ""

    Under this new key, the URL Protocol string value indicates that this key declares a custom protocol handler. Without this key, the handler application will not launch. The value should be an empty string.

    Keys should also be added for DefaultIcon and shell . The Default string value of the DefaultIcon key must be the file name to use as an icon for this new URL protocol. The string takes the form "path, iconindex" with a maximum length of MAX_PATH. The name of the first key under the shell key should be an action verb, such as open . Under this key, a command key or a DDEEXEC key indicate how the handler should be invoked. The values under the command and DDEEXEC keys describe how to launch the application handling the new protocol.

    Finally, the Default string value should contain the display name of the new protocol. The following example shows how to register an application, alert.exe in this case, to handle the alert protocol.

    HKEY_CLASSES_ROOT 
         alert 

              (Default) = "URL:Alert Protocol"
              URL Protocol = ""
              DefaultIcon 
                   (Default) = "alert.exe,1"
              shell 
                   open 
                        command
     
                             (Default) = "C:/Program Files/Alert/alert.exe" "%1"

    When a user clicks a link registered to your custom URL protocol, Internet Explorer launches the registered URL protocol handler. If the specified open command specified in the registry contains a %1 parameter, Internet Explorer passes the URL to the registered protocol handler application.

    Launching the Handler

    By adding the above settings to the registry, navigating to URLs such as alert:Hello%20World would cause an attempt to launch alert.exe with the complete URL on the command line. Internet Explorer decodes the URL, but the Windows Run... command does not. If a URL contains spaces, it may be split across more than one argument on the command line.

    For example, if the link above is followed through Internet Explorer, the command line would be:

    "C:/Program Files/Alert/alert.exe" "alert:Hello World"

    If this link is followed through Windows Explorer, the Windows Run command, or some other application, the command line would be:

    "C:/Program Files/Alert/alert.exe" "alert:Hello%20World"

    Because Internet Explorer will decode all percent-encoded octets in the URL before passing the URL to ShellExecute , URLs such as alert:%3F? will be given to the alert application protocol handler as alert:?? . The handler won't know that the first question mark was percent-encoded. To avoid this issue, application protocol handlers and their associated URL scheme must not rely on encoding. If encoding is necessary, protocol handlers should use another type of encoding that is compatible with URL syntax, such as Base64 encoding. Double percent-encoding is not a perfect solution either; if the application protocol URL isn't processed by Internet Explorer, it will not be decoded.

    When ShellExecute executes the application protocol handler with the URL on the command line, any non-encoded spaces, quotes, and slashes in the URL will be interpreted as part of the command line. This means that if you use C/C++'s argc and argv to determine the arguments passed to your application, the URL may be broken across multiple parameters. To mitigate this issue:

    • Avoid spaces, quotes, or backslashes in your URL
    • Quote the %1 in the registration ("%1" as written in the 'alert' example registration)

    However, avoidance doesn't completely solve the problem of quotes in the URL or a backslash at the end of the URL.

    Security Issues

    As noted above, the URL that is passed to an application protocol handler might be broken across multiple parameters. Malicious parties could use additional quote or backslash characters to pass additional command line parameters. For this reason, application protocol handlers should assume that any parameters on the command line could come from malicious parties, and carefully validate them. Applications that could initiate dangerous actions based on external data must first confirm those actions with the user. In addition, handling applications should be tested with URLs that are overly long or contain unexpected (or undesirable) character sequences.

    For more information, please see Writing Secure Code .

    Example Protocol Handler

    The following sample code contains a simple C# console application demonstrating one way to implement a protocol handler for the alert protocol.

    using System;
    
    using System.Collections.Generic;
    
    using System.Text;
    
    
    
    namespace Alert
    
    {
    
      class Program
    
      {
    
        static string ProcessInput(string s)
    
        {
    
           // TODO Verify and validate the input 
    
           // string as appropriate for your application.
    
           return s;
    
        }
    
    
    
        static void Main(string[] args)
    
        {
    
          Console.WriteLine("Alert.exe invoked with the following parameters./r/n");
    
          Console.WriteLine("Raw command-line: /n/t" + Environment.CommandLine);
    
    
    
          Console.WriteLine("/n/nArguments:/n");
    
          foreach (string s in args)
    
          {
    
            Console.WriteLine("/t" + ProcessInput(s));
    
          }
    
          Console.WriteLine("/nPress any key to continue...");
    
          Console.ReadKey();
    
        }
    
      }
    
    }

    When invoked with the URL alert:"Hello%20World" (note extra quotes) from Internet Explorer, the program responds with:

    Alert.exe invoked with the following parameters.
    
    
    
    Raw command-line:
    
            "C:/Program Files/Alert/alert.exe" "alert:"Hello World""
    
    
    
    
    
    Arguments:
    
    
    
            alert:Hello
    
            World
    
    
    
    Press any key to continue...
    
    

    0
    0

    展开全文
  • 多态的方法调用

    2018-10-12 09:52:08
    第一题: public class Demo { ... public static void main(String[] args) { Base b = new SubClass(); System.out.println(b.x); System.out.println(b.method()); } } class Base { ...
  • 主函数中调用其他文件内的函数

    千次阅读 2016-05-19 11:44:14
    就是再写个头文件,对调用文件里的函数进行申明。再将头文件写主函数所在的文件里。如下面所示: //文件a.c #include "a.h" int display(int a,int b){ cout return 0; } //文件a.h #include int display(int ,...
  • H5与原生app交互,需要WebViewJavascriptBridge,废话不多直接上代码,下面是项目的封装bridge.js的全部代码(示例代码为vue) //iOS 交互声明 function connectWebViewJavascriptBridgeIOS(callback) { if ...
  • java调用某个类的构造方法的时候,系统总会调用父类的非静态初始化块进行初始化,这个调用是隐式的,而且父类的静态初始化代码 块总是会被执行,接着调用父类的一个或者多个构造器执行初始化,这个调用也可以...
  • EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); checkEglError("After eglCreateContext", egl); return context; } public void destroyContext(EGL10...
  • gnuplot_i 为我们完成这项工作,它提供了一组简单、友好的程序接口,可以让我们轻松的程序中调用GNUPLOT 完成复杂的图形显示功能。 当前版本的gnuplot_i 包含2个程序文件:  gnuplot_i.c  gnuplot_i.h ...
  • RMI远程方法调用讲解教程

    千次阅读 2004-11-09 13:59:00
    RMI远程方法调用讲解教程1、RMI概述RMI(Remote Method Invocation)RMI是分布式对象软件包,它简化了多台计算机上的JAVA应用之间的通信。必须jdk1.1以上RMI用到的类java.rmi.Remote所有可以被远程调用的对象都...
  • AS3 中调用JS代码

    千次阅读 2012-05-07 17:08:02
    package { import flash.display.Sprite; import flash.external.... * 测试AS3 中调用js代码,或是AS3中调用自定义js代码 * @author Jave.Lin */ public class Main extends Sprite { public funct
  • tp 控制器调用(自身方法调用

    千次阅读 2016-04-26 09:39:41
    public function index(){ // $ob = new OauthController;//其他类的方法调用 // $ob->wxoauth(); // $code = I('get.code'); // $result = $ob->get_wechat_openid($code); // var_dump($resu
  • js调用as方法示例

    千次阅读 2010-01-24 20:33:00
    工作遇到js调用as的情况,所以研究半天...以下是网页的flash代码(注意object定义好id)------------------------------------------------------------------------------ AC_FL_RunContent( codebase,http://do
  • 实现两个数相加:Computer输入数据,由CPU进行计算,Display显示器显示出结果; Computer类: package Nandu; import java.util.Scanner; public class Computer {  public Cpu cpu;//创建CPU类的对象...
  • 父类与子类之间变量和方法调用

    千次阅读 2013-09-15 23:53:35
    java调用某个类的构造方法的时候,系统总会调用父类的非静态初始化块进行初始化,这个调用是隐式的,而且父类的静态初始化代码 块总是会被执行,接着调用父类的一个或者多个构造器执行初始化,这个调用也可以...
  • 用tkinter写的主页面 并且主页面中用按钮实现了调用游戏界面并且关闭主页面的方法,现在需要一个返回按钮 返回tk的主页面 我现在点按钮可以返回但是无法关闭当前的pygame的窗口 求助各位大神 import ...
  • 网上有些例子只给了简单的print,不能充分说明问题。既然希望C里调用C++的函数
  • java调用某个类的构造方法的时候,系统总会调用父类的非静态初始化块进行初始化,这个调用是隐式的,而且父类的静态初始化代码 块总是会被执行,接着调用父类的一个或者多个构造器执行初始化,这个调用也可以...
  • display:grid的使用方法

    千次阅读 2019-03-20 10:45:19
    display: grid; grid-template-columns: 200px auto; grid-template-rows: 50px auto 50px; grid-template-areas: "header header" "sidebar main" "footer footer"; } //声明容器是grid,并将列分为200px,和auto ...
  • java父类调用被子类重写的方法

    千次阅读 2014-02-19 15:44:57
    1.如果父类构造器调用了被子类重写的方法,且通过子类构造函数创建子类对象,调用了这个父类构造器(无论显示还是隐式),就会导致父类构造时实际上调用的是子类覆盖的方法(你需要了解java继承的初始化机制)。...
  • 查看ida的函数调用

    万次阅读 2018-02-06 16:36:10
    一个样本想要查看一个函数调用了那些函数,有2个办法: 1、View->Open subviews->Function calls 显示出函数调用窗口,如下: 显示的很详细,而且不冗余。 2、点击按钮Display graph of xrefs from ...
  • cocos2d-x lua c++ 相互调用代码直接调用注册 我用的是 cocos2d-x 2.2.2 我也是参考 himi博客的文章 但是他那个我没有跑通 不多废话 下面是我的代码  如有lua api 等疑问点开链接看himi的文章 ...
  • android调用最新的谷歌地图方法

    千次阅读 2015-05-15 17:17:53
    最近项目设计国外用户,有些心得,现在给出国内来调用谷歌地图、定位的方法。 一、.要用谷歌服务当然要满足调用谷歌服务对开发环境以及手机运行环境的要求:  1. 开发环境要满足,以方便自己可以调用google map...
  • java基础-反射3(反射,反射创建对象,操作对象属性,调用对象方法)前面通过学习,我们了解的运行时类型信息的基本原理,以及通过Class对象和反射来获取运行时类型信息。下面来了解通过反射来创建对象,以及操作...
  • 父类调用子类重写方法---------多态

    千次阅读 2019-08-23 16:51:59
    1.如果父类构造器调用了被子类重写的方法,且通过子类构造函数创建子类对象,调用了这个父类构造器(无论显示还是隐式),就会导致父类构造时实际上调用的是子类覆盖的方法(你需要了解java继承的初始化机制)。...
  • LabWindows/CVI 调用dll的方法

    万次阅读 2015-08-18 15:55:54
    LabWindows/CVI 调用dll的方法: dll文件的编写 (1)打开软件Labwindows/CVI,点击File->New->project新建一个工程*.prj,如图所示。然后保存为example.prj。 (2)用同样的方式,新建一个*.c文件,...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 122,147
精华内容 48,858
关键字:

在main方法中调用display