oop - Project in c++, making a phonebook -
i tried , looked everywhere on internet, can't seem find much.
now, without talking, problem have: have make project college consists of making "electronic phone-book" using oop programming logic in c++. materials i`ve received extremely vague must on own somehow.
here code have done far(with internet):
#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 contact"); getch(); } void op4() { printf("\n find contact"); getch(); } void op5() { printf("\n sort contacts"); getch(); } void op6() { printf("\n 'about 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 contact"); printf("\n4. find contact"); printf("\n5. sort contacts"); printf("\n6. about"); printf("\n7. exit"); printf("\n\n##############################"); printf("\n\ninput 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 , computer science"); printf("\n study program used: c++\n\n"); centertext("c++ project"); centertext("<the phonebook>"); printf("\n"); centertext("<my name, year of study, group>"); printf("\n"); printf("\n"); centertext("<june.2013>"); system("pause>nul"); // screen paused until key pressed (to allow text viewed) } // ... sequence 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 exit...\n"); getch(); return; } printf("\n\npassword correct !\n"); printf("the program executed !\n"); getch(); } char optiune; // ... sequence option choosing ... { 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); } the idea maybe use menu in way like, inserting in 1 of op() functions redirect file, 1 function in separate file. have program main program , each function "adds, edits, deletes ..etc outside of program , deal them separately. thing ..i have no clue in doing so. i've looked in "header" working system , didn't find of value there. maybe don't know trust me i've tried. feedback appreciated, remember extremely newbie in this. please, if can, explain detail can. appreciate read entire thing. thank beginning.
you can't find anywhere, "i have make project college". presumably have instructors and/or professors learn? other that, introductory c++ book ever written cover you're asking for, here.
you "using oop programming logic in c++", yet don't use oop other built in io classes.
indent code properly.
don't use these:
#include <conio.h> getch() system("cls")you're mixing calls
printf()std::cout, , callsscanf()std::cin- pick 1 or other, , never usescanf().if you're using c++, using
std::stringbetter this:void centertext(char* s)the cast here unnecessary, when you're assigned
intit'll automatically convert:int pos=(int)((80-l)/2);main()returnsint, don't this:void main()you can't
fflush(stdin), flushing not defined on input streams.don't put things on 1 line this, because looks awful:
case '1': op1(); break;it's better
return 0exit(0)under normal circumstances,exit(0)not destroy objects.
Comments
Post a Comment