Hi there! I am looking for assistance in helping me understand 3 assignment questions. Please help in pointing me in the right direction so I can actually start the questions. I am posting my questions here for experts to help me understand what I am meant to do in each specified question. This subject is not my major. Your help in this matter would be greatly appreciated. Q1. Function callings are indispensible in just about every C++ program that is supposed to be able to achieve something non-trivial. To refresh ourselves, explain the difference between passing by value and passing by reference in function calling. Use your own concrete C++ code to exemplify your explanations. >>>>>>>I dont quite understand the question. c++ code #include <iostream> using namespace std; int main () { ????????????? int a=1,b=2; do i do a loop ??? Q2. This is for the implementation of the menu options 1. to 3.. For simplicity, we assume that the total number of marks to be analysed will not exceed 1000 within the program. When menu option 1. is selected, the program will let you add just one mark before returning you to the menu. When menu option 2. is selected, the program will list all the marks which have been added so far, some of which may be equal in value, then pause the screen for viewing before returning to the menu again. When menu option 3. is selected, the program will calculate and display the average of all the added marks, before returning again to the menu. You are welcome to design your program in whichever way you wish, as long as it is consistent with the general design principles. However, you are also welcome to implement the following prototyped functions or their variants for this purpose 16. bool addMark(double allMarks[], int &totalRec, double &mark); 17. bool displayMarks(double allMarks[], int totalRec); 18. bool findMean(double allMarks[], int totalRec, double &mean); where the array allMarks is assumed to contain totalRec number of valid marks, mark may be used to pass back the actual mark successfully added, and mean may be used to pass back the average of all the marks. The bool value returned by a function may be used to indicate whether the operation has been successful or not. >>>>>> I don't even understand this question (NEED HELP) but, Code: #include <iostream> bool isPrimeNumber(long); int main(void) { int numPrimesFound = 0; for (long i = 2; i < 1000; i++) { if (isPrimeNumber(i)) { numPrimesFound++; std::cout << "Prime #" << numPrimesFound << ": " << i << std::endl; } } return 0; } bool isPrimeNumber(long num) { if (num < 2) return false; else if (num == 2) return true; else { for (long i = 2; i < num; i++) { if (num % i == 0) return false; } } system ("pause"); return true; } Q3. This is for the implementation of the menu options 6. and 7.. When menu option 6. is selected, the program will first read a mark from the user, and then search the available list of marks to see how many occurrences of this mark there are. It will then report this number of occurrences. When menu option 7. is selected, the program will go through all the distinctive marks in the list, and find out how many occurences there are for each of the distinctive marks. For instance, if the current list of marks contains 24. 56, 67, 86, 56, 56, 67, 77 then the menu option 7. should generate something similar to MARKS OCCURRENCES 56 3 67 2 86 1 77 1 >>>> I need someone to explain this question, as I don't understand it... ????
Q1 "do I do a loop?" No, the question is "explain the difference between passing by value and passing by reference" - Google it if you don't remember what this means. Here are some hits to get you started: http://lmgtfy.com/?q=pass+by+value+pass+by+reference Then it says to give code examples, so you would want two functions (to keep it simple) - one with pass by value and one using the other, perhaps modify what is passed in, then after the function calls display the results, and explain why the results would be different. Q2 OK, break it down and take it step by step. You'll find it's not as difficult as it seems. The first sentence mentions a menu with options 1-3. Use that as a starting point: Code: int main() { for (;;) { printf("Menu\n----\n\n"); printf("1. Enter mark\n"); printf("2. List marks\n"); printf("3. Display average\n"); printf("\nEnter a value : "); char buf[32]; fgets(buf,30,stdin); int opt=atoi(buf); switch (opt) { case 1: enter_mark(); break; case 2: display_marks(); break; case 3: display_avg(); break; } } } The second mentions stuff will be stored, and that it will not exceed 1000 elements. So we need an array of size 1000, correct? You can determine the type later, although maybe int, maybe double, depends on whether the marks are integer or floating point. And so on. I don't understand why you posted code that calculates prime numbers in relation to a question about averaging a bunch of stuff, but if you don't understand the question then maybe any guess will do. Q3. Again, break it down and take it one step at a time. What happened to 4&5? Anyway, what does 6 do? Would you need to extend the above menu program to allow for this (Hint: Yes)? The program will read...OK, that means input. You know how to do that, right? Then search...Can you figure that one out? ...how many occurrences...OK, so you need a counter that will be incremented each time the entered mark is found. And so on. Same with 7, which is a little more complicated. You need to identify the distinct marks in the list, so that means you need a second list (again, this won't need to be greater than 1000 in size). Scan through the first, and put unique entries into the second. So if the first list contains 1,1,1,4,4,9, then the second will contain 1,4,9. Then you need to count how many of each there are, so maybe a 3rd array (also 1000 long because the user might enter 1000 different values), and for the same example the results would be 3,2,1 (because there are 3 1's, 2 4's and one 9). Take it a bit at a time. Implement one part, and compile and test BEFORE you move onto the next. Yes, I really said BEFORE. Do not write hundreds of lines of code before compiling it; this isn't an essay, and the compiler doesn't care how many times you compile the program. Write at most 5-10 lines of code and ensure it works before you move onto the next. Display interim results if you need to, to ensure those lines work correctly. This - really! - is how I write code, after having done it for >30 years including >20 professionally.
hi! Thank you for taking the time to explain this to me. I really appreciate it and it is very useful. I had to re-read what I was meant to do. Thanks again!