我尝试并在互联网上到处寻找,我似乎找不到太多。
现在,不用多说,我的问题是:我必须为大学制作一个项目,其中包括使用 C++ 中的 OOP 编程逻辑制作“电子电话簿”。我收到的材料非常模糊,所以我必须以某种方式自己做。
这是我到目前为止所做的代码(在互联网的帮助下):
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include <fstream.h>
void op1()
{
printf("\n Add contact");
getch();
}
void op2()
{
printf("\n Delete contact");
getch();
}
void op3()
{
printf("\n Edit a contact");
getch();
}
void op4()
{
printf("\n Find a contact");
getch();
}
void op5()
{
printf("\n Sort the contacts");
getch();
}
void op6()
{
printf("\n 'About the program, details etc. etc.");
getch();
}
void print_menu()
{
system("cls"); // clearing window
printf("\nMenu:");
printf("\n##############################\n");
printf("\n1. Add contact");
printf("\n2. Delete contact");
printf("\n3. Edit a contact");
printf("\n4. Find a contact");
printf("\n5. Sort the contacts");
printf("\n6. About");
printf("\n7. Exit");
printf("\n\n##############################");
printf("\n\nInput your option: ");
}
// Text centering function - begin
void centerText(char* s)
{
int l=strlen(s);
int pos=(int)((80-l)/2);
for(int i=0;i<pos;i++)
cout<<" ";
cout<<s<<endl;
}
// Text centering functon - end
void main()
{
{
printf("\n 'My University' 'My City' ");
printf("\n Faculty of Electrical Engineer and Computer Science");
printf("\n Study program used: C++\n\n");
centerText("C++ Project");
centerText("<The Phonebook>");
printf("\n");
centerText("<my name, Year I of study, Group>");
printf("\n");
printf("\n");
centerText("<june.2013>");
system("pause>nul"); // Screen is paused until a key is pressed (to allow this text to be viewed)
}
// ... Sequence for password verification ...
{
char password[20], my_password[20]="2013";
system("cls");
printf("WARNING!\n");
printf("Authentication required!\n");
printf("\nType input password: ");
scanf("%19s",password);
if (strcmp(password, my_password)!=0)
{
printf("\n\nIncorrect password !!!\n");
printf("The program will now exit...\n");
getch();
return;
}
printf("\n\nPassword is correct !\n");
printf("The program is executed !\n");
getch();
}
char optiune;
// ... Sequence for option choosing ...
do
{
print_menu();
fflush(stdin);
cin>>optiune;
switch(optiune)
{
case '1': op1(); break;
case '2': op2(); break;
case '3': op3(); break;
case '4': op4(); break;
case '5': op5(); break;
case '6': op6(); break;
case '7': exit(0);
default : printf("\n\nIncorrect option !");
fflush(stdin);
getch();
}
}
while(1);
}
我的想法是,我可以以某种方式使用此菜单,只需在其中一个 op() 函数中插入重定向到另一个文件,该文件是单独文件中的 1 个函数。所以我会把这个程序作为一个主程序,每个“添加、编辑、删除..etc的功能都在这个程序之外,我会单独处理它们。事情是..我不知道这样做。我查看了“标题”工作系统,但我并没有真正找到任何有价值的东西。也许我不知道看但相信我,我真的试过了。非常感谢任何反馈,但请记住我是非常新手。如果可以,请尽可能详细地解释。我感谢阅读整本书的任何人。我会感谢开头的。