Help me please!!

Never mind, figured it out.
Last edited on
Please note, that this is not a homework site.
We won't do your homework for you.
The purpose of homework is that you learn by doing.
However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.


We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.
Hi,
We are not here to do home works :|
if you need any help about starting project and how to write classes, you're welcome, but if you want to get hole complete project, im sorry, i cant do it.

**NOTE: if you want to start, its my first guide, think its a simple LinkedList, and Contact class is your node, so, code it as a node for your Linked list (i mean, you should have a pointer in that class, like node *next; ).
then ContactList, is your LinkedList class, so, you need an Obj, and *head (Or any other way you prefer to define a Linked list)
and finally, use them in MobilePhone class.
if you need help to code them, feel free to ask, but start coding at first by your self.

yes, thank you amirtork.

not looking for someone to do this work for me. just point me in the right direction.

missed class due to the flue and I'm a little lost on the whole class system stuff.

I'll try tackling the first part and post later. Appreciate the help.
Okay, so this is what I got so far. Please help if you can and add good comments. I think I'm getting it but still unsure.



Design requirements:

1. Create a new class type called Contact. The purpose of the Contact class is to model a single contact in a phone contact list.
The Contact type should have the following attributes:

a. First name
b. Last name
c. Phone number

==============================================================================================================================

//This is the function used for making contacts
Class Contact

//The class is made up of 3 strings which form one contact.
Declare String FirstName;
Declare String LastName;
Declare String PhoneNumber;

End Class

==============================================================================================================================

2. Create a new class type called ContactList. The purpose of the ContactList class is to manage an array of contacts. The ContactList
class should have the following characteristics:

a. An attribute should be defined to contain an array of Contact instances.
b. The constructor function of the class should initialize the array of Contacts to 10 elements in size.
c. There should be a function called AddContact. The function should accept a Contact as a parameter. When invoked, the function will
assign the Contact into the array into the appropriate element that will maintain the list in sorted order by last name. The function
does not return anything. If there are not enough slots left in the array to store the contact, then the original array should be
replaced by a new array that is double in size. You will need to keep track of how large your array was made.
d. There should be a function called FindContact. The function should accept two strings that represent the first and last name to search
for. If there is a contact in the array that matches the first and last name given, then the function should return the phone number
of the contact that was matched. Otherwise, the function should return an empty string (“”).
e. There should be a function called GetCount. This function should simply return how many contacts were added to the array.
f. There should be a function called GetSize. The function should return the capacity of the contact list (how big the array currently is).

==============================================================================================================================

//This function sets the qualities of the Class Contact and limits itself to 10 instances
Class ContactList

//Creating an array of contacts called "phonebook"
Declare Contact[] phoneBook;

//constructor function that will be auto called when you make a variable of type contactlist
ContactList()

//Defines the length of the array
phoneBook=Contact[10];

//Defines the qualities of the Class with F, L and P
Int f,l,p

//
NumbersAdded = ref AddContact intCount


//This sub function allows the user to add contacts to the Contact List
AddContact (ref ContactList, Count, InputY, InputN)

//Sets the contact index to 0
Declare Count = 0
Declare ContactList[] = Count

//Sets up a counter with limit to 10 instance
From 0 - 9 Count

//Keeping constraint on the Contact List
If Count < 9 then;

//User interface
Print "Would you like to add a new contact?";
InputY = Yes;
InputN = No;

//Error Message
If Input != InputY, InputN, then;
Print "Please try again.";
End if

Print "Enter First Name";
ContactList[Count].f = First Name;

Print "Enter Last Name";
ContactList[Count].l = Last Name;

Print "Enter Phone Number";
ContactList[Count].p = Phone Number;

Print "Contact stored";

End If;

End AddContact


Function ContactListSort (ref ContactList[ ].l, Int arraySize)

//Contains the last subscript of the last element to be compared within the array.
DECLARE integer maxElement;

//This is used as a counter in the loop.
DECLARE integer index;

//maxElement is set at the end of the array to be compared during each pass of the
//array. It is initially set as the index of the last element and then it decreases by one
//with each iteration.
FOR maxElement = arraySize - 1 to 0 Step -1;

//The inner loop goes through the array two at a time and compares adjacent
// elements. All the elements from 0 to maxElement are compared. If they are
// out of order, the module sends them to another sub module to be swapped.
FOR index = 0 to maxElement - 1;

//Compares two adjacent array elements and swaps if necessary.
IF array [index] > array [index + 1] THEN;
Call swap array[index], array[index + 1];

END IF;
END FOR;
END FOR;
END MODULE

// This is the actual swapping Module for the bubbleSort.
MODULE CompareContacts(String Ref ContactList.l1, String Ref ContactList.l2)

// Temporarily holds a value while it is swapped.
DECLARE String temp;

//Swap the values in ContactList.l1 and ContactList.l2
SET temp = ContactList.l1;
SET ContactList.l1 = ContactList.l2;
SET ContactList.l2 = temp;

END MODULE
Is that supposed to be your pseudocode?

Your ContactList class should also have an attribute such as size to keep track of the size of your dynamic array.

//Defines the qualities of the Class with F, L and P
Int f,l,p

This doesn't belong in ContactList class or in the constructor function ContactList(). Not sure what it's supposed to do...

//
NumbersAdded = ref AddContact intCount

You didn't comment anything here so I'm assuming that NumbersAdded is an attribute of your ContactList class to keep track of how much of the dynamic array is actually filled.

Declare ContactList[] = Count

Huh?

//Sets up a counter with limit to 10 instance
From 0 - 9 Count

//Keeping constraint on the Contact List
If Count < 9 then;

//User interface
Print "Would you like to add a new contact?";
InputY = Yes;
InputN = No;

//Error Message
If Input != InputY, InputN, then;
Print "Please try again.";
End if

Print "Enter First Name";
ContactList[Count].f = First Name;

Print "Enter Last Name";
ContactList[Count].l = Last Name;

Print "Enter Phone Number";
ContactList[Count].p = Phone Number;

Print "Contact stored";

End If;

Instead of 9, use size (the attribute in the ContactList class that you should have had). Instead of ContactList[Count], it should be phoneBook[Count]. According to requirements, you are supposed to have a check here for how many contacts have been added. If the phoneBook[] is full, double the size of the array.
Last edited on
Long story short, missed both lectures on classes and construction of classes.

So I've been trying to reference online tutorials but I'm just lost.

All notes are greatly appreciated. I'll post my progress later.
The classes should look something like this, according to the requirements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
struct Contact
{
	std::string firstName;
	std::string lastName;
	std::string phoneNumber;
};

class ContactList
{
	private:
		Contact *phoneBook;
		unsigned int arraySize;
		unsigned int numContacts;
	public:
		ContactList();
		~ContactList() { delete[] phoneBook; }
		void AddContact(const Contact& c);
		void Sort();
		std::string FindContact(std::string f, std::string l);
		unsigned int getCount() { return numContacts; }
		unsigned int getSize() { return arraySize; }
};

ContactList::ContactList()
{
	//fill in the constructor function
}

void ContactList::AddContact(const Contact& c)
{
	//check that numContacts < arraySize
	//if false, double the size of the phoneBook array
	//add c to phoneBook
	//call Sort()
}

void ContactList::Sort()
{
	//sort the phoneBook
}

std::string FindContact(std::string f, std::string l)
{
	//fill in the code for the function
}
Last edited on
Topic archived. No new replies allowed.