狗gou富贵 狗gou富贵
是一個人
关注数: 4 粉丝数: 15 发帖数: 238 关注贴吧数: 25
萌新求教1. 指出程序中的错误,说明原因,并指出哪些顶层co 萌新求教 1. 指出程序中的错误,说明原因,并指出哪些顶层const,哪些是底层const #include <iostream> #include<string> using namespace std; int main(){ string *pstr = "c++"; const string ss= "Java" + *pstr; const string ss= "Java"; char str[] = "Python"; const char *const ps = str; str[4] = 'e'; ps[1] = 'o'; pstr = ss; string &const rs = ss; return 0; } 2. 给出程序的输出结果,如有错误,请改正 #include <iostream> #include<string> using namespace std; void print(int x = 3) { cout << ”call for void print(int x = 3)” << endl; cout << "x = " << x << endl; } void print(string s1 = "hello", string s2) { cout << “call for void print(string s1 = ”hello“, string s2)“ << endl; cout << s1 + "," + s2; } int main() { print(5); print(); print("world"); print(); return 0; } 3. 给出程序的输出结果,如有错误,请改正 #include <iostream> #include<string> using namespace std; void print(const string &s1) { cout << "call for void print(const string &s1)" << endl; cout << s1; } void print(string &s1) { cout << "call for void print(string &s1)" << endl; cout << s1; } void print(string s1) { cout << "call for void print(string s1)" << endl; cout << s1; } int main() { print("world"); return 0; } 4. 给出程序的输出结果,如有错误,请改正 #include <iostream> using namespace std; float temp; float area(float r) { temp = r*r*3; return temp; } float& area(float r) { temp = r*r*3; return temp; } int main() { float a1 = fn1(5.0); float& a2 = fn1(5.0); float& a3 = fn2(5.0); float a4 = fn1(4) = 10; float a5 = fn2(4) = 20; cout << a1 << endl; cout << a2 << endl; cout << a3 << endl; cout << a4 << endl; cout << a5 << endl; return 0; }
萌新求教 这个程序运行后 只能使用一次 基于链表结构实现一个简单的通讯录管理系统,实现通讯录的简单电子化。该系统具有增加新纪录,修改原记录,删除原纪录,根据姓名查找和查看所有记录等功能。 #include<bits/stdc++.h> using namespace std; struct stud_node{ char name[20]; struct stud_node *next; }; struct stud_node * InsertDoc(struct stud_node * head, struct stud_node *stud); struct stud_node * DeleteDoc(struct stud_node * head, char *name); struct stud_node * FindDoc(struct stud_node * head,char *name); int Print_Stu_Doc(struct stud_node * head); int main() { struct stud_node *head,*p; int choice; char name[20]; int size = sizeof(struct stud_node); head=nullptr; cout<<"1.增加新记录\n"<<"2.修改原记录\n"<<"3.删除原纪录\n"<<"4.根据姓名查找\n"<<"5.查看所有记录\n"<<"6.out\n"<<endl; cin>>choice; switch(choice) { case 1: printf("增加人员的信息"); printf("姓名:"); scanf("%s",name); p = (struct stud_node *) malloc(size); strcpy(p->name, name); p->next=nullptr; head=InsertDoc(head, p); break; case 2: printf("修改信息"); scanf("%s", name); if ((p=FindDoc(head,name)) !=NULL) { printf("录入信息:\n"); printf("姓名:"); scanf("%s",p->name); } else printf("no\n"); break; case 3: printf("删除信息;\n"); scanf("%s",name); if ((p=FindDoc(head,name)) !=NULL) head = DeleteDoc(head, name); else printf("no\n"); break; case 4 : printf ("查找姓名\n"); scanf("%s",name); if ((p=FindDoc(head,name)) !=NULL) { printf("姓名:%s\n",p->name); } else printf("no\n"); break; case 5: Print_Stu_Doc(head); break; case 6: break; } while(choice != 6); return 0; } struct stud_node * InsertDoc(struct stud_node * head, struct stud_node *stud) { struct stud_node *ptr; ptr = stud; if(head == NULL) { head = ptr; head->next = NULL; } else { ptr->next=head; head=ptr; } return head; } struct stud_node * DeleteDoc(struct stud_node * head, char *name) { struct stud_node *ptrl, *ptr2; while(head!=NULL && strcmp(head->name,name) == 0) {ptr2 = head; head = head->next; free(ptr2); } if(head == NULL) return NULL; ptrl = head; ptr2 = head->next; while(ptr2!=NULL){ if(strcmp(ptr2->name,name) == 0) { ptrl->next = ptr2->next; free(ptr2);} else ptrl = ptr2; ptr2 = ptrl->next; } return head; } int Print_Stu_Doc(struct stud_node * head) { struct stud_node * p; if(head == NULL){ printf("\nno\n"); } printf("记录:\n"); p = head; while ( p!=NULL) { printf("姓名:%s\n",p->name); } } struct stud_node * FindDoc(struct stud_node * head,char *name) { struct stud_node * p=head; while(p!=NULL) { if(strcmp(p->name,name)==0) return p; else p=p->next; } return p; }这样之后按什么都无效
1 下一页