Help on couple of easy computer science questions?

Click For Summary

Discussion Overview

The discussion revolves around a set of computer science questions related to memory calculation, conditional statements, and short-circuit evaluation in programming. Participants seek clarification on their answers and understanding of the concepts involved.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant questions how to calculate the memory required for a 512x512 color image with 256 levels of color, expressing confusion over their initial guess.
  • Another participant suggests that the first question requires understanding how many bits are needed to encode 256 levels of color per pixel and the total bits for the image.
  • For the conditional statements, participants discuss the values of x that satisfy various conditions, with one participant initially providing incorrect answers and later acknowledging that there are multiple correct answers for some conditions.
  • There is a discussion about the definition of a pixel and its relevance to the memory calculation question.
  • Participants express uncertainty about the necessity of showing work for the problems, with some believing that certain questions do not require detailed explanations.

Areas of Agreement / Disagreement

Participants generally agree that more work needs to be shown for the questions, particularly for the conditional statements. However, there is no consensus on the necessity of showing work for all questions, as some participants believe certain problems can be solved without it.

Contextual Notes

Participants express varying levels of understanding regarding the concepts of pixels, memory calculation, and conditional logic, indicating a need for further clarification on these topics.

Who May Find This Useful

Students studying computer science, particularly those learning about memory management, conditional statements, and programming logic.

zzoo4
Messages
42
Reaction score
0
I got my old tests back today. And I don't understand what i did wrong??
p.s. teacher is not available at the moment( sub//part time teacher).

1. How much memory does it take to hold a 512x512 color image with 256 different levels of color(states)??

Okay, this one I just guessed and divided 8bits by 262144 which is totally wrong..

2a. what values of x will cause the following to be true??
if(x<100 && x>0 && x%2==1) for this i put 99..

b. if (x>=0 && x%5==0) for this i put 5.

c. if (Math.sqrt(x))%1 == 1 && x>1 && x<50 ) i put 12.25 (okay obviously this is wrong).

3. Create an example of short-circuit evaluation with an || (OR) statement = include variable with explanation.

i put if ((x==y) || (y==x) b/c if one condition is true, the other one must be true.

4. Create an example of a short-circuit evaluation with an && (AND) statement. Include values and explanation.

i put if ((x!=y) || (y=x) b/c only one condition needs to be false , then other is false.



help me fix what I did wrong please?
 
Physics news on Phys.org
zzoo4 said:
I got my old tests back today. And I don't understand what i did wrong??
p.s. teacher is not available at the moment( sub//part time teacher).

1. How much memory does it take to hold a 512x512 color image with 256 different levels of color(states)??

Okay, this one I just guessed and divided 8bits by 262144 which is totally wrong..

2a. what values of x will cause the following to be true??
if(x<100 && x>0 && x%2==1) for this i put 99..

b. if (x>=0 && x%5==0) for this i put 5.

c. if (Math.sqrt(x))%1 == 1 && x>1 && x<50 ) i put 12.25 (okay obviously this is wrong).

3. Create an example of short-circuit evaluation with an || (OR) statement = include variable with explanation.

i put if ((x==y) || (y==x) b/c if one condition is true, the other one must be true.

4. Create an example of a short-circuit evaluation with an && (AND) statement. Include values and explanation.

i put if ((x!=y) || (y=x) b/c only one condition needs to be false , then other is false.



help me fix what I did wrong please?

You need to show more work on these questions. We are not able to offer much help (within the PF rules) if you just say you guessed at answers and show no work.

That said, on 1a) Your guess makes absolutely no sense. How many bits does it take to encode 256 levels of color per pixel? And if you have 512x512 pixels, how many total bits is that? How many bytes is that?
 
berkeman said:
You need to show more work on these questions. We are not able to offer much help (within the PF rules) if you just say you guessed at answers and show no work.

That said, on 1a) Your guess makes absolutely no sense. How many bits does it take to encode 256 levels of color per pixel? And if you have 512x512 pixels, how many total bits is that? How many bytes is that?


well, All I knew was bytes =8 bits. And there are 2^8= 256states..
I do not know what pixels are. And I just multiplied 256 by 256 and divided by 8bits.. Which wass wrong.
And for the rest of questions I am pretty sure that those don't really need work to be solved.
 
zzoo4 said:
well, All I knew was bytes =8 bits. And there are 2^8= 256states..
I do not know what pixels are. And I just multiplied 256 by 256 and divided by 8bits.. Which wass wrong.
And for the rest of questions I am pretty sure that those don't really need work to be solved.

A pixel is each dot on your display. You are correct that it takes 8 bits or 1 byte to encode each of the pixels. If there are 512x512 pixels, then how many bytes does it take to hold that 512x512 image?

And no, on the rest of the problems you can definitely show work. Please try to work out 2b) here -- what do each of the terms mean in the question? What is the intersection of those terms?
 
okay. I e-mailed the teacher, and I get how to do em now.

He said I got couple of them wrong due to questions have more answer.
for example.

2b. is 0 and all positive multiples of 5
 
berkeman said:
A pixel is each dot on your display. You are correct that it takes 8 bits or 1 byte to encode each of the pixels. If there are 512x512 pixels, then how many bytes does it take to hold that 512x512 image?

And no, on the rest of the problems you can definitely show work. Please try to work out 2b) here -- what do each of the terms mean in the question? What is the intersection of those terms?

if (x>=0 && x%5==0) // since x is greater than and equal to 0 and divided by 5 gives no remainder. it has to be either 0 or and thing multiple of 5. ex. 55%5==0.
So there's clearly more answer than just the number 5.

o and all positive multiples of 5
 
zzoo4 said:
if (x>=0 && x%5==0) // since x is greater than and equal to 0 and divided by 5 gives no remainder. it has to be either 0 or and thing multiple of 5. ex. 55%5==0.
So there's clearly more answer than just the number 5.

o and all positive multiples of 5

Good. Can you do them all now?
 
yessirr
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 12 ·
Replies
12
Views
2K