![]() |
| | #1 |
| Registered User Join Date: Jul 2008
Posts: 38
| Homework help Here are the requirements for the assignment: 1. Do not add any nonsense in my C code, for my lecturer will not accept any nonsense added in my code!!! 2. Be able to demonstrate and explain programs to your lecturer. 3. Submit a physical file holding the following: a) Printed hard copy of all programs b) Printed test cases c) All soft copy programs in a CD-R (please attach firmly to physical file) 4. Do what is exactly asked in the questions. The assignment is worth 40 points. The deadline is July 25, 2008, so you better hurry up. Question 1 (24 points) Question 1 contains 12 sub-questions which will be in separate C programs. I'll be the one who will design the filenames for each program. Each of the functions below needs to be run in a program. Each of the programs should have at least one test case (with a screen capture) which shows the succesful running of the program. Each sub-question is worth 2 points. a) Write a function called ChangeToNext that takes in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y'. If ch == 'Z', the function returns 'A'. You may assume that the character parameter ch is always an uppercase alphabetic character. b) Write a function called Difference that takes in an integer array intarr of size 10. The function returns the difference between the sum of all values from cell 0 to 4 and the sum from cell 5 to 9. For example, if intarra[10]={1,1,1,1,1,2,2,2,2,2}, Difference (intarr) returns -5 ((1+1+1+1+1) - (2+2+2+2+2) c) Write a function PerimeterMinusCenter that takes in a two-dimensional array called intarr of 3 rows and 3 columns. The function sums the values in the perimeter of the array. It then returns the difference of this sum and the center value (the value in cell row 1, column 1 or [1][1]). For example, if Code: intarr[3][3] = {1,1,1}
{1,2,1}
{1,1,1}
};
d) Write a function Compare that takes in a two-dimensional array called intarr of 3 rows and 3 columns. The function sums up separately the values in the diagonal of the array and the non-diagonal values. It then compares these two sums and return 1 if the diagonal sum is larger than the non-diagonal sum or 0 otherwise. For example, if Code: intarr[3][3] = {{1,2,2}
{2,1,2}
{2,2,1}
};
e) Write a recursive function called CountEvenASCII that takes in a string parameter str and return the number of characters with even ASCII codes. For example CountEvenASCII("ABCDE") returns 2 (as B and D are of even ASCII codes). f) Change your solution above (sub-question e) into an iterative solution. g) Write a function called ReturnNextCase that takes in a character parameter ch and returns the next alphabet in the other case. For example, ChangeCase('A') returns 'b' and ChangeCase('a') returns 'B'. You may always assume the character parameter ch is always alphabetic. h) Write a function called ReturnASCIIDifference that takes in a string parameter str. The function sums up separately even ASCII characters and odd ASCII characters and return their difference. For example, ReturnASCIIDifference('ABCD') returns 2 (as the ASCII values of 'A', 'B', 'C', and 'D' are 65, 66, 67, and 68 respectively and (66+68) - (65+67) = 2). i) Write a function called CheckPosNeg that takes in a reference integer parameter num. The function returns 0 if the content of the reference parameter is a positive number and 1 otherwise. j) Write a function called PrintToZero that takes in a reference integer parameter num. The function prints out the content of num up to zero. For example, if *num=10, then PrintToZero(num) prints 10 9 8 7 ... 0.. Last edited by mkdl750; 07-03-2008 at 09:56 PM. Reason: additional info |
| mkdl750 is offline | |
| | #3 |
| Registered User Join Date: Jul 2008
Posts: 38
| Sorry, sir, I'm just a noob and I need you help. Please post the codes if necessary. |
| mkdl750 is offline | |
| | #4 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,139
| But it's your assignment? Read http://cboard.cprogramming.com/annou...t.php?f=4&a=39 What happens when you finish your course (if you do...)? They're testing you, not us. If you have a specific question, feel free to ask. ie, part 'a': Code: char ChangeToNext(char ch)
{
/* insert code here */
}
Last edited by zacs7; 07-03-2008 at 10:27 PM. |
| zacs7 is offline | |
| | #5 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| If you put as much effort into your programming as you do with your presentation and sucking up skills, then you might actually get somewhere. http://www.catb.org/~esr/faqs/smart-....html#homework
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #6 |
| Registered User Join Date: Jul 2008
Posts: 38
| Okay sorry about that I'll be the one to design the codes myself and need further help later on. |
| mkdl750 is offline | |
| | #7 |
| Registered Abuser Join Date: Jun 2006 Location: Toronto
Posts: 572
| requesting obligatory posting of mac's signature and lock... in that order.
__________________ MSDN knows exactly what you're looking for... |
| @nthony is offline | |
| | #8 |
| Registered User Join Date: Jul 2008
Posts: 38
| Code: #include <stdio.h>
char ChangeToNext(char ch);
main()
{
char x;
printf("Enter uppercase letter: ");
fflush(stdin);
scanf("&c",&x);
if (x == 'A' || x == 'B' || x == 'C' || x == 'D' || x == 'E' || x == 'F' ||
x == 'G' || x == 'H' || x == 'I' || x == 'J' || x == 'K' || x == 'L' ||
x == 'M' || x == 'N' || x == 'O' || x == 'P' || x == 'Q' || x == 'R' ||
x == 'S' || x == 'T' || x == 'U' || x == 'V' || x == 'W' || x == 'X' ||
x == 'Y' || x == 'Z')
{
ChangeToNext(x);
}
else
{
printf("\nWrong character. Try again.\n");
}
getch();
return 0;
}
char ChangeToNext(char ch)
{
printf("\nThe next alphabet letter is: ");
if (ch == 'A')
{
printf("B");
}
else if (ch == 'B')
{
printf("C");
}
else if (ch == 'C')
{
printf("D");
}
else if (ch == 'D')
{
printf("E");
}
else if (ch == 'E')
{
printf("F");
}
else if (ch == 'F')
{
printf("G");
}
else if (ch == 'G')
{
printf("H");
}
else if (ch == 'H')
{
printf("I");
}
else if (ch == 'I')
{
printf("J");
}
else if (ch == 'J')
{
printf("K");
}
else if (ch == 'K')
{
printf("L");
}
else if (ch == 'L')
{
printf("M");
}
else if (ch == 'M')
{
printf("N");
}
else if (ch == 'N')
{
printf("O");
}
else if (ch == 'O')
{
printf("P");
}
else if (ch == 'P')
{
printf("Q");
}
else if (ch == 'Q')
{
printf("R");
}
else if (ch == 'R')
{
printf("S");
}
else if (ch == 'S')
{
printf("T");
}
else if (ch == 'T')
{
printf("U");
}
else if (ch == 'U')
{
printf("V");
}
else if (ch == 'V')
{
printf("W");
}
else if (ch == 'W')
{
printf("X");
}
else if (ch == 'X')
{
printf("Y");
}
else if (ch == 'Y')
{
printf("Z");
}
else if (ch == 'Z')
{
printf("A");
}
else
{
printf("\nError.");
}
return;
}
|
| mkdl750 is offline | |
| | #9 |
| Registered User Join Date: Jul 2008
Posts: 38
| I almost forgot the "scanf("&c",&x);" in line 8 is actually "scanf("%c",&x);". Thank you for your consideration in subquestion A. I'm advancing to subquestion B. |
| mkdl750 is offline | |
| | #10 |
| Registered User Join Date: Jul 2008
Posts: 38
| Here is subquestion B. I have to write a function called "Difference" that takes in an integer array "intarr" of size 10. The function returns the difference between the sum of all values from cell 0 to 4 and the sum from cell 5 to 9. For example, if intarra[10]={1,1,1,1,1,2,2,2,2,2}, Difference(intarr) returns -5 ((1+1+1+1+1) - (2+2+2+2+2). Any valuable hints? Here's the start of my code: Code:
#include <stdio.h>
void Difference[int intarr[10]
main()
{ //code goes here
}
|
| mkdl750 is offline | |
| | #11 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
Code: void Difference[int intarr[10] Code: void Difference(int intarr[10]); Also, the global main function returns an int, so you should explicitly define it as such. You should also explicitly return 0 at the end of the global main function, though this is optional with respect to the 1999 edition of the C standard.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #12 |
| Registered User Join Date: Apr 2008
Posts: 83
| Here is your First solution Code:
#include "stdio.h"
char ChangeToNext(char ch);
int main(int argc, char* argv[])
{
char ch;
char Next_ch;
printf("enter the character\n");
scanf("%c", &ch);
Next_ch= ChangeToNext(ch);
printf("%c", ch);
return 0;
}
char ChangeToNext(char ch)
{
if(ch>'Y'&&ch<'N')
{
return ++ch;
}
else if (ch=='N')
{
return 'Y';
}
}
Last edited by laserlight; 07-04-2008 at 12:48 AM. Reason: "Corrected" the code. |
| shwetha_siddu is offline | |
| | #13 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| shwetha_siddu, do not post homework solutions unless it is clear that the member has sufficiently attempted to solve the question. To this end, I have modified your code example so that it will not produce the correct answer. EDIT: Actually, come to think of it, your code is incorrect to begin with since your ChangeToNext() implementation has one control path that does not return a value. Oh well.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way Last edited by laserlight; 07-04-2008 at 12:49 AM. |
| laserlight is online now | |
| | #14 |
| Registered User Join Date: Oct 2007
Posts: 242
| > mkdl, this is a really not a good way to do this. What I do suggest is to use char() - e.g: char(65), output: A Something like this: Code: char GetNext(char a)
{
if(a == 'Z')
return 'A';
else
{
int dec = (int)a + 1;
return char(dec);
}
}
Well, I was kinda bored so... e) Code: int rec(char *str)
{
if(str[0] == '\0')
return 0;
if((int)str[0] % 2 == 0)
return 1 + rec(str + 1);
else
return rec(str + 1);
}
EDIT: If I'm overriding a rule, please edit my post, thanks. Last edited by eXeCuTeR; 07-04-2008 at 03:10 AM. |
| eXeCuTeR is offline | |
| | #15 | |
| Registered User Join Date: Jun 2008
Posts: 1,134
| Quote:
...cause everything is about definitions.... | |
| C_ntua is offline | |
![]() |
| Tags |
| assignment, c programming, homework |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Homework | kermi3 | A Brief History of Cprogramming.com | 11 | 11-03-2001 04:39 PM |
| Homework | kermi3 | C Programming | 10 | 09-27-2001 04:49 PM |
| Homework | kermi3 | C++ Programming | 15 | 09-26-2001 03:16 PM |
| Homework | kermi3 | Windows Programming | 5 | 09-15-2001 11:48 AM |
| Homework | kermi3 | C Programming | 0 | 09-10-2001 01:26 PM |