| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 539 人关注过本帖
标题:求C++编程帮忙(using friend method)
只看楼主 加入收藏
晓宁
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2011-9-7
结帖率:71.43%
收藏
已结贴  问题点数:20 回复次数:3 
求C++编程帮忙(using friend method)
#include<iostream.h>
#include<string.h>

class Point;

class Information
{
    friend class Point;
private:
    char name[30],id[10];
public:
    void setdata(char *,char *);
};

void Information::setdata(char * a,char * b)
{
    strcpy(name,a);
    strcpy(id,b);
}
class Point
{
    int cumulated_point,current_point,total_point;

public:
    void set_point(int,int);
    void calculate_point();
    void display(Information);
};

void Point::set_point(int point1,int point2)
{
    cumulated_point=point1;
    cumulated_point=point2;
}

void Point::calculate_point()
{
    total_point=cumulated_point + current_point;
}

void Point::display(Information a)
{
    cout<<"Member's Name:"<<a.name<<"\n";
    cout<<"ID :"<<a.id<<"\n";
    cout<<"Total Point :"<<total_point<<"\n";

    if (total_point> 1000)
        cout<<"Qualified to be VIP Member.";
    else
        cout<<"Not qualified to be VIP Member.";
    cout<<'\n';
}

void main()
{
    char name[30],id[10];
    int cumulated_point,current_point;
    Point a;
    Information b;
    cout<<"Name:";
    cin.getline(name,30);
    cout<<"ID :";
    cin.getline(id,10);
    cout<<"Cumulated Point :";
    cin>>cumulated_point;
    cout<<"Current Point :";
    cin>>current_point;
    cout<<'\n';
    b.setdata(name,id);
    a.set_point(cumulated_point,current_point);
    a.calculate_point();
    a.display(b);
}
搜索更多相关主题的帖子: 编程 private display include friend 
2011-09-07 12:50
博士无双
Rank: 2
等 级:论坛游民
帖 子:32
专家分:65
注 册:2011-7-5
收藏
得分:20 
#include<iostream>
#include<string>
using namespace std;

class Point;

class Information
{
    friend class Point;
private:
    char name[30],id[10];
public:
    void setdata(char *,char *);
};

void Information::setdata(char * a,char * b)
{
    strcpy(name,a);
    strcpy(id,b);
}
class Point
{
    int cumulated_point,current_point,total_point;

public:
    void set_point(int,int);
    void calculate_point();
    void display(Information);
};

void Point::set_point(int point1,int point2)
{
    cumulated_point=point1;
    current_point=point2;
}

void Point::calculate_point()
{
    total_point=cumulated_point + current_point;
}

void Point::display(Information a)
{
    cout<<"Member's Name:"<<a.name<<"\n";
    cout<<"ID :"<<a.id<<"\n";
    cout<<"Total Point :"<<total_point<<"\n";

    if (total_point> 1000)
        cout<<"Qualified to be VIP Member.";
    else
        cout<<"Not qualified to be VIP Member.";
    cout<<'\n';
}

void main()
{
    char name[30],id[10];
    int cp,cup;
    Point a;
    Information b;
    cout<<"Name:";
    cin.getline(name,30);
    cout<<"ID :";
    cin.getline(id,10);
    cout<<"Cumulated Point :";
    cin>>cp;
    cout<<"Current Point :";
    cin>>cup;
    cout<<'\n';
    b.setdata(name,id);
    a.set_point(cp,cup);
    a.calculate_point();
    a.display(b);
    system("pause");
}
调试过了,没问题
2011-09-07 19:17
晓宁
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2011-9-7
收藏
得分:0 
谢谢您的帮忙
2011-09-07 20:35
晓宁
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2011-9-7
收藏
得分:0 
回复 楼主 晓宁
谢谢您的帮忙
2011-09-07 21:20
快速回复:求C++编程帮忙(using friend method)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.070533 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved