Welcome! Log In Create A New Profile

Advanced

Assignment 3

Posted by Icebabe 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar Re: Assignment 3
June 22, 2006 11:08AM
All sorted, all printed. Now to find the time.. smiling smiley

-Valkeye
Re: Assignment 3
June 22, 2006 02:14PM
Can anyone help me with question 3. I've lost myself in it.....somewhere;
avatar Re: Assignment 3
June 22, 2006 02:29PM
what part is giving you problems?

What's not happening that should be or what's happening that shouldn't be?

-Valkeye
Re: Assignment 3
June 28, 2006 08:00AM
Hi All.....

Im battling to get started with Assignment 3, question 1a. Please could someone explain to me what to do with this question. If possible would you leave your number so I can call one of you who understands this work well.

For now a good explanation of question 1a would also be of great help smiling smiley

thanks
avatar Re: Assignment 3
June 28, 2006 02:22PM
Basically so far the question has given you the skeleton of the main().

You've got 3 arrays(1 string, 2 ints) and a const int Num which indicates the number of old people.

The question has given you 3 tasks.

1) Input the data
2) Display the name and the number of birds seen by the oldest person.
3) Display the name and age of the person who's seen the most birds.

Thats it! Thats all the question asks!

They've said though that to perform these 3 tasks you are only allowed 2 extra functions. inputData(...) and highest(...).

Basically what they're trying to teach here is the ability to make our code re-usable. Task 1 needs the inputData(...), whilst task 2 and 3 need the highest(...).

Within inputData(...) you need to go through a loop and input all the people into the reapective arrays. Names into Names, Ages into Ages, and Birds into Birds.

So, within highest(...) instead of calling your variables things like OldestPerson rather use names such as Largest. Then you have a generic function which takes any int[] and returns the LARGEST INDEX of the array. Be carefull that you don't compare the value of one element with the index of the other!! Very easy mistake to make.

Now we know that we have 3 arrays. position [0] of each array refers to the same person.. as do all the other possitions. So if you determine that Age[6] is the oldest person, you also know that Names[6] and Birds[6] all refer to the data of that oldest person.


Now's just the task of putting it all together....

-Valkeye
Re: Assignment 3
June 28, 2006 11:15PM
hi has anybody done question 3 on strings
not sure where to start
help anybody ???
Re: Assignment 3
June 29, 2006 09:38AM
Deez, I have started, but is not sure how to determine if the length
of the string is a multiple of three.
Any ideas as how to do this?
avatar Re: Assignment 3
June 29, 2006 09:50AM
Hi guys,

if((string.size() % 3) == 0)

that'll determine if the string is a multiple of 3.

Remember that % is the modulus, which divides something by something else and gives the remainder. So, if (string.size() % 3) is equal to 0 then you know that it is a multiple of 3.

-Valkeye
Re: Assignment 3
June 29, 2006 09:50AM
if the length mod 3 = 0 then it is a multiple of 3.
Re: Assignment 3
June 29, 2006 12:37PM
Hi Valkeye,
I did manage to get the if((string.size() % 3) == 0) correct.
I have tried to swop the first third and the last third.
I displayed the first third with:

FirstThird = Text.substr(0,3);

How would one refer to the last third?
Thanks
Icebabe

avatar Re: Assignment 3
June 29, 2006 01:15PM
Hi Icebabe,

first thing you need to do is determine what the exact length of each third is. You know that it's a multiple of three so you can define an integer and assign the length of a third to it.

Then using you substr(...) you can use multiples of the third length to get your start position, and the third length as your length.

eg.

int ThirdLength = Text.size()/3;

You know that it is a multiple of 3 already, so it will always be a whole number and you wont lose accuracy by not assigning it to a float.

Text.substr(0, ThirdLength) <-- First third
Text.substr(ThirdLength, ThirdLength) <-- Second third
Text.substr(ThirdLength*2, ThirdLength) <--Final third

Be aware though, that if you so this assignment over multiple statements, your positions of the thrirds will already start to change and you may need to adjust your statements accordingly. Best to use 1 statement to do the whole calculation... Just make it look neat. Remember, C++ doesn't read the white space characters, unless in a string, so you can use multiple lines for each statement smiling smiley

-Valkeye
Re: Assignment 3
June 29, 2006 01:40PM
Thanks Valkeye,

I will try. Will let you know.
Re: Assignment 3
June 29, 2006 09:22PM
Valkeye,

thanks for the help! I managed to get that part working. grinning smiley
I struggle to get my bool function working and to replace the vowels with '*'
Here is what I tried:

//This is the bool function to determine if the string has
//vowels in it.

bool isVowel(string Changed){
int Pos = Changed.find(Vowel);
while(Pos != -1);
if (Changed == Vowel)
return Changed.size();



//This is in the main function

else {
Pos = Text.find(Vowel);
char X = '*';
if (isVowel(Text))
while (Pos != -1){
Text.replace(Pos, Text.size(), char X);
Pos = Text.find(Vowel);
}


Thanks.
Re: Assignment 3
June 29, 2006 11:02PM
Valkeye,

I have another question, if you don't mind.
In Question 4 you must write a bool function. It should determine if
the string typed starts with "On", if it does it should add it to thearray StartWithOn. How do you add that string to the array?
Here is pieces of what I did:

//the bool function

bool startingWithOn(string WithOn){
int Pos = WithOn.find('On'winking smiley;
if (Pos == true)
return true;
return false;


//int the main function

if (startingWithOn(GivenString));
GivenString == StartWithOn;

Then another question:
How do you define a string that is an array?
Should it be: string StartWithOn[10];

In the question they say that a maximum of 10 strings have to be input.

Thanks
Re: Assignment 3
July 01, 2006 08:22AM
Hi Everyone,

how far are you with assignment 3? It is due today!!
avatar Re: Assignment 3
July 01, 2006 09:09AM
Hi Icebabe,

have u sorted out ur probs?

From what u've posted your bool function is wrong. If you use the find() then you need to compare Pos with 0 (not true as you have done). At the moment if i'm not mistaken your function will only return true if On is the second and third characters in the function (if it even compiles).

Rather use: if(WithOn.substr(0, 2) == "On"winking smiley

In your main function you use your StartingWithOn function and if it returns true you assign the value of the array to the string...? You need to assign the value of the string to the array.

Yes, that is how you define a string[].

Hope it all goes well. Good luck smiling smiley

-Valkeye
Re: Assignment 3
July 01, 2006 10:23AM
Valkeye,

yes, problems sorted, thank you! grinning smiley
Re: Assignment 3
July 05, 2006 02:40PM
Hi Valkeye

i'm also struggling, please help if you can

on q3 i have gotten the program to work in so far as to swop the thirds, ( thanks to your help with IceBabe )

but i my bool function i don't know what to do under the else statement

i took the bool function from the textbook on page 292

must i use a find and replace to change the vowels to *

much appreciated
avatar Re: Assignment 3
July 05, 2006 03:14PM
I haven't used the textbook at all so I don't know what function you're talking about, but....

Just looking at the question again, the function requires you to check each individual char in the string, which means you'll need a for loop running from 0 to MyString.size() in the main function, each iteration calling your isBool(...) with the character in the string at position i(whatever variable you use). Use <, not <=. If the answer returns true then assign that position a *, if not, do nothing, and loop.

Within the function I used a Switch statement:

switch(c){
  case 'A':
  case 'a':
  case 'E':
  case 'e':
  case 'I':
  case 'i':
  case 'O':
  case 'o':
  case 'U':
  case 'u':
    return true;
  default:
    return false;
}

remember that unless you use a break statement each case after the entry point case is executed. Therefore if any of those cases are true all of the statements (which is nothing apart from the last case) will be executed. The last case (u) is a return statement so I don't need a break statement either, and the default case returns false..


Hope this helps.

-Valkeye
Re: Assignment 3
July 05, 2006 04:52PM
I'm really quite far behind, I've only started looking at this module today.
Valkeye, thanks for the pointers you have posted thus far, they are going to come in very handy.
Cheers,
AndreB
Sorry, only registered users may post in this forum.

Click here to login