diff --git a/ProjectREADME.txt b/ProjectREADME.txt new file mode 100644 index 0000000..c8f0179 --- /dev/null +++ b/ProjectREADME.txt @@ -0,0 +1,29 @@ +My Contacts App + +July 15, 2016 +Julia Tan + +Overview +The My Contacts program is designed to be an efficient contacts directory that is simple and user-friendly, yet allows for quick access to contact details. Unlike a regular contact book, this program is able to categorize contacts into groups, and also add ratings, which is especially useful for businesses such as restaurants. + +Functions +This contact book is able to: +- Create and save your contacts +- Add and edit details to each contact, which are name, telephone number, ratings and address +- Create categories to store your contacts under +- Display all your contacts under a category +- Display all categories +- Display contact information of a contact + +How to Use +To navigate through the application, use the number keys to select what you want to do. Options of what the application can do for you at the current time will be displayed on the screen, with correspoinding number choices. + +The program will function until you 'Exit', which is an option that is also displayed on the screen. + +Review +The program is able to do all the functions specified on the project proposal. Input/output, conditional statements, loops, functions, arrays/strings and advanced data types were used to create this program. + +The way I coded it was quite different from how I imagined the game would be written. I used fout functions: the main function, a function that reads the number inputs the user selects, a function that creates new contacts and a function that does different things with the categories. I used a lot of if statements especially in the function that deals with the categories, to do different functions with the categories. + +Reasons for Making this Program +I chose to do this project because I wanted to create a program that someone would be able to benefit from. I also wanted to create a program that would be quite useful, compared to other types of programs such as games. Enjoy! diff --git a/contacts.c b/contacts.c new file mode 100644 index 0000000..902d5e0 --- /dev/null +++ b/contacts.c @@ -0,0 +1,174 @@ +// Julia Tan +// Final Project July 13, 2016 + +#include +#include + +typedef struct contact{ + char name[100]; + int telnum; + char rating[4]; + char address[100]; +}newCon; + +typedef struct category{ + char cname[100]; + int contactCount; + newCon contact[50]; // Contacts are created under categories +}newCat; + +void userSelect(int* a); +void categories(int choice); +void newContact(int categoryNum, newCat* category); + +void userSelect(int* a){ // Process what the user wants to do + scanf("%d", a); + if (*a == 1){ // Create a new contact + categories(1); + }else if (*a == 2){ // View categories + categories(2); + }else if (*a == 3){ // View contacs + categories(3); + }else if (*a == 4){ // Edit details + categories(4); + }else if (*a == 5){ // Exit + + }else{ // Invalid input + printf("\nInvalid selection. Please try again:\n"); + userSelect(a); + } +} + +void newContact(int categoryNum, newCat* category){ // Adds a new contact + int *conCountPtr = &(category[categoryNum].contactCount); // Counts number of contacts within chosen category + char enter; // Checks for \n symbol + int phone; // evaluates scanf + + // Create a new contact + printf("New Contact\n"); + + printf("Enter full name: "); + scanf(" %[^\n]%*c", category[categoryNum].contact[*conCountPtr].name); // reads everything, even space characters, until it hits \n + + do{ // gets phone number and makes sure it is only made of integers + printf("Enter phone number: "); + phone = scanf("%d%c", &category[categoryNum].contact[*conCountPtr].telnum, &enter); + if (phone != 2 || enter != '\n'){ // checks if the only character in input is the \n symbol (this would be true for integer inputs + printf("Invalid number, try again.\n"); + while (getchar() != '\n') // clears input buffer + ; + } + }while (phone != 2 || enter != '\n'); // while the input is not purely an integer value... + + printf("Enter rating: "); + scanf(" %s", category[categoryNum].contact[*conCountPtr].rating); + + while (getchar() != '\n'); + printf("Enter address: "); + scanf(" %[^\n]%*c", category[categoryNum].contact[*conCountPtr].address); + + printf("Contact successfully added.\n\n"); + (*conCountPtr)++; // Increments the number of contacts within the chosen category +} + +void categories(int choice){ // Does category-related work + static int catCount = 0; // counts number of existing categories + static newCat category[10]; // creates an array of categories + newCat *catPtr = category; // pointer to array of categories for functions + static int userIn = 0; // user input for what category they want to put their contacts in + int i = 0; // index for category array + int x = 0; // index for contacts array inside the contacts array + int *conCount = &category[i].contactCount; // pointer to number of contacts in array + int phone; + char enter; + int editChoice; // User's input for choosing what detail of contact to edit + + if (choice == 1){ // Select a category to put your contact in + printf("\nSelect a category to put your new contact in:\n"); + printf("(0) Create a new category\n"); + categories(2); + scanf("%d", &userIn); // Create new category or choose existing + while (userIn == 0){ // While user has chosen to create a new category + catCount++; // Increases count of categories + printf("\nEnter name of new category: "); + scanf(" %[^\n]%*c", category[catCount].cname); // Names new category + category[catCount].contactCount = 0; // Sets number of contacts to 0 + printf("Category successfully created.\n\n"); + + printf("\nSelect a category to put your new contact in:"); + printf("\n(0) Create a new category\n"); + categories(2); + scanf("%d", &userIn); + } + if (userIn <= catCount){ // checks if user input is one of the choices listed + newContact(userIn, catPtr); // arg1 is number of categories, arg2 is pointer to category array + }else{ + printf("\n\nInvalid selection. Please try again: \n\n"); + categories(1); + } + } else if (choice == 2){ // Print categories with contacts underneath + for (i = 1; i <= catCount; i++){ // For each category + printf("\n(%d) %s\n", i, category[i].cname); + for (x = 0; x < category[i].contactCount; x++){ // For each contact under a single category + printf("- (%d) %s\n", x, category[i].contact[x].name); + } + } + } else if (choice == 3){ // Prints categories and contacts + categories(2); + printf("\nSelect category: "); + scanf("%d", &i); + printf("Select contact: "); + scanf("%d", &x); + + for (x = 0; x < category[i].contactCount; x++){ + printf("Name: %s\n", category[i].contact[x].name); + printf("Phone Number: %d\n", category[i].contact[x].telnum); + printf("Rating: %s\n", category[i].contact[x].rating); + printf("Address: %s\n", category[i].contact[x].address); + } + }else if (choice == 4){ // Edits contact Details + int editChoice = 0; // accepts input from user to edit contact details through a menu; + categories(2); + printf("Select category: "); + scanf("%d", &i); + printf("Select contact: "); + scanf("%d", &x); + + printf("\nWhat would you like to edit? (1)Name (2)Number (3)Rating (4)Address\n"); + scanf("%d", &editChoice); + + if (editChoice == 1){ //name + printf("Enter new name: "); + scanf(" %[^\n]%*c", category[i].contact[x].name); + }else if (editChoice == 2){ // tel number + do{ // gets phone number and makes sure it is only made of integers; + printf("Enter phone number: "); // makes sure input is not invalid + phone = scanf("%d%c", &category[i].contact[x].telnum, &enter); + if (phone != 2 || enter != '\n'){ + printf("Invalid number, try again.\n"); + while (getchar() != '\n') + ; + } + }while (phone != 2 || enter != '\n'); + }else if (editChoice == 3){ // rating + printf("Enter new rating: "); + scanf("%s", category[i].contact[x].rating); + }else if (editChoice == 4){ // address + printf("Enter new address: "); + scanf(" %[^\n]%*c", category[i].contact[x].address); + } + + printf("Updated details successfully.\n"); + } +} + +int main(){ + int select = 0; // user's input to questions + int *ptrS = &select; // pointer to user's input (for other functions) + printf("Welcome!\n"); + while (select != 5){ + printf("\nWhat would you like to do? (1)Create a new contact (2)View categories (3)View specific contacts (4)Edit details (5)Exit\n"); + userSelect(ptrS); + } + return 0; +} diff --git a/final.out b/final.out new file mode 100755 index 0000000..1e417d3 Binary files /dev/null and b/final.out differ diff --git a/proposal.txt b/proposal.txt new file mode 100644 index 0000000..23f106e --- /dev/null +++ b/proposal.txt @@ -0,0 +1,48 @@ +Julia Tan + +1. My program will simulate an app that acts as a directory to keep all the user's contacts in place. Unlike a regular contact book, this program would also be able to categorize contacts and add ratings. + +Functions of the program: +- Store contacts +- Categorize contacts into groups such as family, food, clothes +- Create categories +- Add and edit details to each contact, which are name, telephone number, ratings(for businesses especially), category and address +- Display a list of all the contacts under a category +- Display chosen contact's details + +What the program cannot do: +- Text and call + +2. Detailed Examples of Concept Implementation +Input +- takes in contact details from user i.e. name, telephone number, rating, address, category +- takes in category name from user +- takes in commands from user such as to display a list of all contacts in a category, display the chosen contact's details, or edit contact details + +Output +- displaying contact details +- displaying categories +- displaying contacts under a specific category + +Conditional Statements +- Processes user commands to see what they would like to do, such as create a contact, edit contact details, create new category, etc. + +Loops +- For loops to print out contents of a category + +Functions +- Function to add contact details to a category +- Function to create new category +- Function to finish program +- Function to display category contents +- Function to display contact details + +Arrays/strings +- Each category would be an array +- Each contact detail is a string + +Advanced data types: structs +- Each contact would be a struct that would contain name, address, telephone number, rating and category + +3. Reasons for picking this project +I chose to do this project because I wanted to create some kind of 'app' that someone could use on a phone. I also wanted to do something that could be quite useful, compared to games.