Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 28, 2012, 10:05 AM   #176
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

I got an 89 on my my midterm! Made dumb mistakes
oxshannon is offline   0 Reply With Quote
Old Feb 28, 2012, 12:15 PM   #177
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
What dumb mistake did you make?
lloyddean is offline   0 Reply With Quote
Old Feb 28, 2012, 03:02 PM   #178
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
converting a for loop to a while loop
and then there was one "find correct the errors"
and i didnt see cout << Passed << and didnt put quotations on it haha. oops.
oxshannon is offline   0 Reply With Quote
Old Feb 28, 2012, 07:35 PM   #179
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Quote:
Originally Posted by oxshannon View Post
converting a for loop to a while loop
Would you mind elaborating?
lloyddean is offline   0 Reply With Quote
Old Feb 28, 2012, 07:40 PM   #180
mydogisbox
macrumors member
 
Join Date: Jan 2011
Quote:
Originally Posted by lloyddean View Post
Would you mind elaborating?
Is that really necessary? Lets just leave it at: she did decently and she understands the material well.
mydogisbox is offline   0 Reply With Quote
Old Feb 28, 2012, 08:11 PM   #181
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
I wish clarity, I'm not sure why you don't perhaps you should just stop reading!
lloyddean is offline   0 Reply With Quote
Old Feb 29, 2012, 09:24 AM   #182
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
the question gave a for loop and asked to convert it to a while loop and i messed up
oxshannon is offline   0 Reply With Quote
Old Feb 29, 2012, 09:54 AM   #183
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
I think lloyddean was asking in what way you messed that up. Did you get the exit condition wrong? The increment location? ...

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Mar 1, 2012, 09:52 AM   #184
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

Quote:
Originally Posted by balamw
I think lloyddean was asking in what way you messed that up. Did you get the exit condition wrong? The increment location? ...

B
We didn't get to keep our tests so I'm not sure I can exactly remember. I think I left out I= whatever it was supposed to equal. I only got like 2 points taken off so it wasn't a big deal
oxshannon is offline   0 Reply With Quote
Old Mar 8, 2012, 08:23 PM   #185
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
hi guys im back. your friendly neighbourhood amateur computer programmer.

i need help with this question.


2 Given the following array declarations:
(1) double a[30];
(2) int s(6) = {1, 2, 3, 4, 5, 6};
(3) int s[4] = {1, 2, 3, 4, 5};
(4) char[30] r;
(5) int s[] = {1, 2, 3, 4, 5};
(6) char str[] = “hello”;

Which of the following statements is correct?
(a) (2), (3) and (4) are wrong and the rest are correct.
(b) Only (1) and (6) are correct.
(c) Only (1) and (5) are correct.
(d) None of the above.


lol i know its probably not hard but arrays make no sense to me.. and i cant tell when soemthing is right/wrong



and


1 Which one is the correct function definition?
(a) void square(int &x)
{
int y ;
y = x*x;
cout << y << endl;
return y;
}

(b) square(int &x)
{
int y = x*x;
cout << y << endl;
return y;
}

(c) int square(int &x)
{
int y ;
y = x*x;
cout << y << endl;
}

(d)
void square (int &x)
{
int y = x*x;
cout << y << endl;
}

could someone tell me what exactly is wrong with the problems that are wrong?
i think the correct answer is d, because if its void you dont have a return, right?

Last edited by oxshannon; Mar 8, 2012 at 09:09 PM.
oxshannon is offline   0 Reply With Quote
Old Mar 8, 2012, 08:33 PM   #186
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: USA
If you need help with your homework, read your C++ book, or ask your teacher or a fellow student.
robvas is offline   0 Reply With Quote
Old Mar 8, 2012, 09:06 PM   #187
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Quote:
Originally Posted by robvas View Post
If you need help with your homework, read your C++ book, or ask your teacher or a fellow student.
i already explained my prof is extremely difficult to talk to and i dont know anyone in the class, thanks for the advice though mom
oxshannon is offline   1 Reply With Quote
Old Mar 8, 2012, 09:10 PM   #188
thundersteele
macrumors 68030
 
Join Date: Oct 2011
A few hints:

i) read about arrays in C++
ii) put the code in your program, hit compile. If the compiler throws an error, the code is probably wrong
iii) A function has to return the type that it was defined as, e.g. float has to return a float value, void shouldn't return anything


I'm surprised that all function examples pass the reference to the variable. Can someone explain why this would be good/bad?



http://www.cplusplus.com/doc/tutorial/arrays/
thundersteele is offline   0 Reply With Quote
Old Mar 8, 2012, 09:14 PM   #189
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Quote:
Originally Posted by thundersteele View Post
A few hints:

i) read about arrays in C++
ii) put the code in your program, hit compile. If the compiler throws an error, the code is probably wrong
iii) A function has to return the type that it was defined as, e.g. float has to return a float value, void shouldn't return anything


I'm surprised that all function examples pass the reference to the variable. Can someone explain why this would be good/bad?
my book just confused me more, sadly. im trying, i promise. its not that i want you guys to just tell me the answer or anything lol im just confused and want to know the rationale behind some things.


edit:: thanks for the link
oxshannon is offline   0 Reply With Quote
Old Mar 8, 2012, 09:25 PM   #190
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
i feel like 1, 3 and 5 in the first question i posted are correct, but theres no option for them. UGH this is so frustrating.

jk 3 is wrong isnt it?
oxshannon is offline   0 Reply With Quote
Old Mar 8, 2012, 09:40 PM   #191
thundersteele
macrumors 68030
 
Join Date: Oct 2011
Quote:
Originally Posted by oxshannon View Post
i feel like 1, 3 and 5 in the first question i posted are correct, but theres no option for them. UGH this is so frustrating.

jk 3 is wrong isnt it?
The array is defined as having length 4, but is initialized with an array of length 5.
thundersteele is offline   0 Reply With Quote
Old Mar 8, 2012, 09:42 PM   #192
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Quote:
Originally Posted by thundersteele View Post
The array is defined as having length 4, but is initialized with an array of length 5.
it threw me off for a second because i know the index starts at 0, but i get it now.

so am i correct in saying that 1 and 5 are the only correct ones, would you agree? i really hope im right. lol

and the other questioni posted i THINK im right in saying the answer is d. so again, thanks for the helpppp
oxshannon is offline   0 Reply With Quote
Old Mar 8, 2012, 09:48 PM   #193
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Quote:
Originally Posted by thundersteele View Post
A few hints:
I'm surprised that all function examples pass the reference to the variable. Can someone explain why this would be good/bad?
http://www.cplusplus.com/doc/tutorial/arrays/
Explain, no. Perhaps they were writen by a mad man!

None of them modify 'x' and if that really is what was meant should probably be modified to:

Code:
<return-type> square(const int &x)
But would be better written as:

Code:
<return-type> square(int const x)
lloyddean is offline   0 Reply With Quote
Old Mar 9, 2012, 02:54 AM   #194
thundersteele
macrumors 68030
 
Join Date: Oct 2011
Quote:
Originally Posted by oxshannon View Post
it threw me off for a second because i know the index starts at 0, but i get it now.

so am i correct in saying that 1 and 5 are the only correct ones, would you agree? i really hope im right. lol

and the other questioni posted i THINK im right in saying the answer is d. so again, thanks for the helpppp
Well, if you go back to that link I posted earlier, the chapter after arrays handles character sequences. That should help understand whether or not (6) is correct.
thundersteele is offline   0 Reply With Quote
Old Mar 9, 2012, 07:43 AM   #195
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
im confused whether its right or not, i dont think it is, but icant explain why very well. it just looks wrong in comparison to the examples on that site. for instance

Code:
	char str[] = “hello”;
thats what im talking about btw.
oxshannon is offline   0 Reply With Quote
Old Mar 9, 2012, 07:45 AM   #196
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by oxshannon View Post
2 Given the following array declarations:
(1) double a[30];
(2) int s(6) = {1, 2, 3, 4, 5, 6};
(3) int s[4] = {1, 2, 3, 4, 5};
(4) char[30] r;
(5) int s[] = {1, 2, 3, 4, 5};
(6) char str[] = “hello”;

Which of the following statements is correct?
(a) (2), (3) and (4) are wrong and the rest are correct.
(b) Only (1) and (6) are correct.
(c) Only (1) and (5) are correct.
(d) None of the above.
I hate multiple choice questions. Why not let the student mark each of 1 to 6 as correct or incorrect?

(1) is correct. Just an array of thirty doubles.
(2) is wrong. Uses the wrong brackets.
(3) is wrong. Too many initialisers.
(4) is just horrible. I don't care whether it is right or not, you should never write this. I think it's wrong. (That's the difference between language lawyer and developer. I don't care if its right, I wouldn't write it that way and I wouldn't let you write it that way).
(5) is correct. You get an array with five ints.
(6) is correct. A string literal can be used to initialise an array of char. If the array has no size then it gets an extra element for the trailing zero at the end of the string, so you get six chars. char str [5] = "hello"; would also be correct (no trailing zero), char str [4] = "hello"; would be wrong.

Practical tip: Let's say you have an array that should contain 57 constants. You wrote the code but you're not sure if you missed a constant or have one too many. So you declare the array with size 56, compile it and make sure that it fails. Then change the size to 57 compile it and make sure it doesn't fail.
gnasher729 is offline   0 Reply With Quote
Old Mar 9, 2012, 08:52 AM   #197
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Quote:
Originally Posted by gnasher729 View Post
I hate multiple choice questions. Why not let the student mark each of 1 to 6 as correct or incorrect?

(1) is correct. Just an array of thirty doubles.
(2) is wrong. Uses the wrong brackets.
(3) is wrong. Too many initialisers.
(4) is just horrible. I don't care whether it is right or not, you should never write this. I think it's wrong. (That's the difference between language lawyer and developer. I don't care if its right, I wouldn't write it that way and I wouldn't let you write it that way).
(5) is correct. You get an array with five ints.
(6) is correct. A string literal can be used to initialise an array of char. If the array has no size then it gets an extra element for the trailing zero at the end of the string, so you get six chars. char str [5] = "hello"; would also be correct (no trailing zero), char str [4] = "hello"; would be wrong.

Practical tip: Let's say you have an array that should contain 57 constants. You wrote the code but you're not sure if you missed a constant or have one too many. So you declare the array with size 56, compile it and make sure that it fails. Then change the size to 57 compile it and make sure it doesn't fail.
Those are the ones I thought were right, just dont like guessing blindly by going off other examples, i like to know why. Thanks a lot!!!
oxshannon is offline   0 Reply With Quote
Old Mar 9, 2012, 10:34 AM   #198
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Code:
#include <iostream>
using namespace std;
#include <cstdlib>
#include <ctime>
#include <iomanip>
using std::setw;

int main()
{
	const int arraySize = 10;
	int freq [arraySize] = {0};
	
	srand(time(0));
	for (int i = 1; i <=100; i++)
		++freq [rand()%10];

	cout << "Number" << setw(13) << "Frequency" << endl;
		for (int i = 1; i < arraySize; i++)
			cout << setw(6) << i << setw(13) << freq[i] << endl;

	return 0; 
}
Here is what I'm trying to accomplish with this code:

Counting single digits) Write a program that generates one hundred random integers between 0 and 9 and displays the count for each number. Hint: use rand()%10 to generate a random number between 0 and 9. Use an array of ten integers, say frequency, to store the counts for the number of 0’s, 1’s, …, 9’s. Finally, output the frequency for each number.

My problem is I'm getting outputs where the frequency doesn't add up to 100, and also it doesn't display 0. I'm not sure what to do to fix this. Advice

EDIT: False alarm, I figured it out. I set i = 1 instead of 0 because I'm a dummmy.

Last edited by oxshannon; Mar 9, 2012 at 10:41 AM.
oxshannon is offline   0 Reply With Quote
Old Mar 9, 2012, 10:37 AM   #199
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Hint:

Code:
const int arraySize = 9;
How many digits between 0 and 9 inclusive?

EDIT: You were quick to edit the post.

Next look at this line. What do you expect it to do?

Quote:
for (int i = 1; i < arraySize; i++)
B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   1 Reply With Quote
Old Mar 9, 2012, 11:08 AM   #200
oxshannon
Thread Starter
macrumors regular
 
Join Date: Jan 2012
Quote:
Originally Posted by balamw View Post
Hint:

Code:
const int arraySize = 9;
How many digits between 0 and 9 inclusive?

EDIT: You were quick to edit the post.

Next look at this line. What do you expect it to do?



B
also realized i should have set i = 0. im being careless haha.

i have another problem i have to do where it acts me to input two real numbers , r and θ and return two numbers, x and y. according to x = r cos θ and y = r sin θ. i assume i need to use reference parameters. but i dont understand how to use θ in the program? can i use that as a variable in c++?
oxshannon is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
[mac mini or imac for] xcode grandM iPhone/iPad Programming 27 Mar 7, 2014 11:51 AM
Where is my gcc and g++ compiler sysProgrammer Mac Programming 10 Nov 24, 2013 06:47 PM
Moving from xcode 3.2 to xcode 4.5.2 compilation error for 'abs' macro in stdlib.h hrishidev Mac Programming 7 Jun 2, 2013 10:36 AM
Broken C compiler dancks Mac Programming 2 Jun 15, 2012 03:04 PM
xcode on mac mini erfg12 iPhone/iPad Programming 4 Jun 12, 2012 10:07 AM

Forum Jump

All times are GMT -5. The time now is 06:33 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC