| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:求能被C#调用的C++通讯录
只看楼主 加入收藏
伍则帝
Rank: 3Rank: 3
来 自:四川省南充市高坪区
等 级:论坛游民
威 望:6
帖 子:100
专家分:34
注 册:2013-3-16
结帖率:84%
收藏
已结贴  问题点数:15 回复次数:5 
求能被C#调用的C++通讯录
不要骂我嚎。
小弟因为没有学过C++,是学C#的。
但老师最近布置了一个作业,说是要用C++做功能C#做界面的通讯录。
本想上网下一个的,但下下来的全是控制台的。不知道怎么转换!
所以要问各们大侠们求助!
搜索更多相关主题的帖子: 通讯录 控制台 
2013-10-08 16:01
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:15 
要学习下vc的基本编程才好做。没有直接转换的

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-10-08 16:29
伍则帝
Rank: 3Rank: 3
来 自:四川省南充市高坪区
等 级:论坛游民
威 望:6
帖 子:100
专家分:34
注 册:2013-3-16
收藏
得分:0 
哦,可是我们明后天就要交了呀,来不及了。
看来以后真要好好学下C++了。
不过能不能给我做一个嘛,不要多复杂就行。
只要能实现增,删,查,显示,改。就行!
拜托了!
2013-10-08 16:42
伍则帝
Rank: 3Rank: 3
来 自:四川省南充市高坪区
等 级:论坛游民
威 望:6
帖 子:100
专家分:34
注 册:2013-3-16
收藏
得分:0 
我这里就有个完整的,能不能改下嘛。
CSharpInvokeCPP.rar (4.25 MB)
2013-10-08 16:46
伍则帝
Rank: 3Rank: 3
来 自:四川省南充市高坪区
等 级:论坛游民
威 望:6
帖 子:100
专家分:34
注 册:2013-3-16
收藏
得分:0 
对了,用单链表做的会不会好一点。
2013-10-08 16:56
Morueda
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-23
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OK 1      // OK代表操作成功
#define ERROR 0   // ERROR代表操作失败
///////////////////////////////////////
//    定义结构体TepletePhone用来存放数据
typedef struct TepletePhone
{
    char id[12];
    char sex[10];
    char name[20];
    char adress[20];
    char PhoneNum[12];
    char Email[20];
    struct TepletePhone *next;
}LinkNode,*HeadNode;
//////////////////////////////////
//    将建立好的链表输入到文件中
void write(HeadNode head);
//////////////////////////////////
//    5统计总人数
size_t Cound(void);
//////////////////////////////////
//    2按学号进行删除操作
int Delete(HeadNode head,int num);
//////////////////////////////////
//    4用学号进行查询
int Found(const char *id);
//////////////////////////////////
//    初始化管理界面
void InitGraph(void);
//////////////////////////////////
//    进行选择处理
void Choose(void);
//////////////////////////////////
//    初始化通讯录
void InitNum(HeadNode *head);
/////////////////////////////////
//  1插入操作
int InsertNum(HeadNode head,int num,LinkNode node);
/////////////////////////////////
// 3 查看通讯录
void ShowNum(void);
/////////////////////////////////////
//    主函数
int main(void)
{
    InitGraph();
    Choose();
    return 0;
}
//////////////////////////////////////
//    初始化链表(建立学生信息)
void InitNum(HeadNode *head)
{
    *head = (HeadNode)malloc(sizeof(LinkNode));
    if (*head == NULL)
    {
        printf("内存分配失败\n");
        exit(EXIT_FAILURE);
    }
    else
        (*head)->next = NULL;
}
/////////////////////////////////////
//    功能1.按位置插入
int InsertNum(HeadNode head,int num,LinkNode node)
{
    int i = 0;
    LinkNode *ptail,*pnew;
    ptail = head;
    if (num <= 0)
        return ERROR;
    while (i < num-1 && ptail != NULL)
    {
        ptail = ptail->next;
        i++;
    }
    if (ptail == NULL)
        return ERROR;
    else
    {
        pnew = (LinkNode *)malloc(sizeof(LinkNode));
        if (pnew == NULL)
        {
            printf("分配内存失败\n");
            exit(EXIT_FAILURE);
        }
        *pnew = node;
        pnew->next = ptail->next;
        ptail->next = pnew;
        return OK;
    }
}
///////////////////////////////////////
//    功能3.显示
void ShowNum(void)
{
    char show[100];
    FILE *fp;
    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
        printf("文件打开失败\n");
    while (fgets(show,99,fp) != NULL)
        printf("%s",show);
    printf("\n");
    fclose(fp);
}
/////////////////////////////////////
//    初始化界面
void InitGraph(void)
{
    printf("*******同学通讯管理********\n");
    printf("*1. 插入.\n");
    printf("*2. 删除.\n");
    printf("*3. 显示.\n");
    printf("*4. 查询.\n");
    printf("*5. 统计.\n");      
    printf("*6. 修改.\n");
    printf("*7. 退出.\n");
    printf("***************************\n");
}
//////////////////////////////////////
//    用于选择,提供功能
void Choose(void)
{
    int number,insert;
    char num[20],num1[100];
    LinkNode node;
    while (1)
    {
        printf("请输入你需要进行的操作,以回车结束输入:");
        scanf("%d",&number);
        switch(number)
        {
        case 1:{
                    HeadNode head;
                    InitNum(&head);
                    FILE *fp;
                    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
                        printf("文件打开失败\n");
                    fgets(num1,99,fp);
                    for (number = 0; number < Cound(); number++)
                    {
                        fscanf(fp,"%s%s%s%s%s%s",node.id,
                        node.name,node.sex,node.adress,
                        node.PhoneNum,node.Email);
                        if (InsertNum(head,number+1,node) == ERROR)
                            exit(EXIT_FAILURE);
                    }
                    printf("请输入需要新建学生的信息\n");
                    printf("*请输入学号:");
                    scanf("%s",node.id);
                    printf("*请输入姓名:");
                    scanf("%s",node.name);
                    printf("*请输入性别:");
                    scanf("%s",node.sex);
                    printf("*请输入家庭住址:");
                    scanf("%s",node.adress);
                    printf("*请输入电话号码:");
                    scanf("%s",node.PhoneNum);
                    printf("*请输入E-mail:");
                    scanf("%s",node.Email);
                    printf("*请输入需要插入的位置:");
                    scanf("%d",&insert);
                    if (InsertNum(head,insert,node) == ERROR)
                    {
                        printf("插入操作失败\n");
                        exit(EXIT_FAILURE);
                    }
                    write(head);
               }break;
        case 2:{
                    FILE *fp;
                    HeadNode head;
                    InitNum(&head);
                    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
                        printf("文件打不开\n");
                    fgets(num1,99,fp);
                    for (number = 0; number < Cound(); number++)
                    {
                        fscanf(fp,"%s%s%s%s%s%s",node.id,
                        node.name,node.sex,node.adress,
                        node.PhoneNum,node.Email);
                        if (InsertNum(head,number+1,node) == ERROR)
                            exit(EXIT_FAILURE);
                    }
                        printf("请输入需要删除第几位学生的信息:");
                        scanf("%d",&insert);
                        if (Delete(head,insert) == ERROR)
                        {
                            printf("删除操作失败\n");
                            exit(EXIT_FAILURE);
                        }
                        write(head);   
               }break;
        case 3: ShowNum(); break;
        case 4:    {
                    printf("请输入需要查询的学号:");
                    scanf("%s",num);
                    if (Found(num) == ERROR)
                        printf("查询失败\n");
                }break;
        case 5:    printf("通讯录中有%u个学生的信息\n",Cound()); break;
        case 6:{
                    HeadNode head;
                    InitNum(&head);
                    FILE *fp;
                    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
                        printf("文件打开失败\n");
                    fgets(num1,99,fp);
                    for (number = 0; number < Cound(); number++)
                    {
                        fscanf(fp,"%s%s%s%s%s%s",node.id,
                        node.name,node.sex,node.adress,
                        node.PhoneNum,node.Email);
                        if (InsertNum(head,number+1,node) == ERROR)
                            exit(EXIT_FAILURE);
                    }
                    printf("请输入需要更改的学生号:");
                    char item[20],change[20];
                    scanf("%s",item);
                    LinkNode *p = head->next;
                    for (number = 0; number < Cound(); number++)
                        if (p != NULL && strcmp(item,p->id) == 0)
                            break;
                        else
                            p = p->next;
                    printf("请输入需要更改的数据项:");
                    scanf("%s",item);
                    printf("请输入新的数据项:");
                    scanf("%s",change);
                    int num;
                    if (strcmp(item,"姓名") == 0)
                        strcpy(p->name,change);
                    if (strcmp(item,"学号") == 0)
                        strcpy(p->id,change);
                    if (strcmp(item,"性别") == 0)
                        strcpy(p->sex,change);
                    if (strcmp(item,"家庭住址") == 0)
                        strcpy(p->adress,change);
                    if (strcmp(item,"电话号码") == 0)
                        strcpy(p->PhoneNum,change);
                    if (strcmp(item,"E-mail") == 0)
                        strcpy(p->Email,change);
                    write(head);
               }break;
        case 7: return; break;
        default: printf("操作失败,"
                "请输入正确的操作\n"); break;
        }
    }
}
//////////////////////////////////////
//    功能4.按学号查询
int Found(const char *id)
{
    FILE *fp;
    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
    {
        printf("文件打开失败\n");
        return ERROR;
    }
    char test[20],found[100];
    int flag = 0;
    size_t count = 0;
    while (fscanf(fp,"%s",test) != EOF)
    {
        if(strcmp(test,id) == 0)
        {
            fgets(found,99,fp);
            flag = 1;
            printf("%s",id);
            printf("%s",found);
            if (count == Cound()*6)
                printf("\n");            //    为了最后一行有换行
            break;
        }   
        count++;
    }
    if (flag == 0)
        return ERROR;
    else
        return OK;
    fclose(fp);
}
///////////////////////////////////
//    统计总人数
size_t Cound(void)
{
    FILE *fp;
    char num[100];
    if ((fp = fopen("D:\\B1231.txt","r")) == NULL)
        printf("打开文件失败\n");
    size_t count = -1;
    while (fgets(num,99,fp) != NULL)
        count++;
    fclose(fp);   
    return count;
}
///////////////////////////////////////
//    将链表写入文件函数
void write(HeadNode head)
{
    FILE *fp;
    LinkNode *p = head->next;
    fp = fopen("D:\\B1231.txt","w");
    fprintf(fp,"%s\t%s\t%s\t%s\t%s\t%s\n",
        "学号","姓名","性别","家庭住址",
        "电话号码","E-mail");
    while (p != NULL)
    {
        fprintf(fp,"%s\t%s\t%s\t%s\t\t%s\t%s\t",
            p->id,p->name,p->sex,p->adress,
            p->PhoneNum,p->Email);
        if (p->next != NULL)            //    为了最后一行少一个换行
            fprintf(fp,"%s","\n");
        p = p->next;
    }
    fclose(fp);
}
//////////////////////////////////////
//    删除节点(删除学生信息)
int Delete(HeadNode head,int num)
{
    int i = 0;
    LinkNode *pnext,*now;
    pnext = head;
    while (pnext->next != NULL && i < num-1)
    {
        pnext = pnext->next;
        i++;
    }
    if (pnext->next == NULL)
        return ERROR;
    now = pnext->next;
    pnext->next = now->next;
    free(now);
    return OK;
}

你再改一下
2013-10-23 12:48
快速回复:求能被C#调用的C++通讯录
数据加载中...
 
   



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

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