Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C p

72 views
Skip to first unread message

somurg...@gmail.com

unread,
Apr 19, 2016, 3:05:13 PM4/19/16
to
1. Construct your own library by generating .c and .h files. Your library should include the following functions:
a. sumOfIntegersDivisibleBy3(n) : returns sum of integers divisible by 3 between 1 and n.
b. factorial(n) : returns factorial of the number n
c. power(x,y) : calculates xy
d. isDivisible(x,y) : finds whether x is divisible by y. i.e. isDivisible(35,5) returns 1, isDivisible(32,5) returns 0
2. Write a program that includes your library. In the main function you will have a loop with sentinel continuation condition. You should allow the user to select any of the functions provided by your library to make some calculations. Use switch statement to execute the selected operation. When the user makes a selection, according to the selected operation print some directives to the screen, take arguments from the user and print the result. Then the program should wait for the next selection.
For all coding, you should provide very detailed comments within your code. Please select function names and variable names self-commenting as well. Do not use math standard library functions.
You are encouraged to prepare your functions in pseudocode first. However, this assignment does not require submission of your pseudocodes.
Example user interface should be similar to the following (red entries represent the user inputs):
Please make a selection with the corresponding number of any operation:
1. sumOfIntegersDivisibleBy3
2. factorial
3. power
4. is divisible
9. Exit
3
Please enter two integers x and y to calculate x^y
2 3
Result is: 8
Please make a selection with the corresponding number of any operation:
1. sumOfIntegersDivisibleBy3
2. factorial
3. power
.
.

Richard

unread,
Apr 19, 2016, 3:08:33 PM4/19/16
to
[Please do not mail me a copy of your followup]

We won't do your homework for you.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Barry Schwarz

unread,
Apr 19, 2016, 6:17:43 PM4/19/16
to
On Tue, 19 Apr 2016 12:04:50 -0700 (PDT), somurg...@gmail.com
wrote:

>1. Construct your own library by generating .c and .h files. Your library should include the following functions:

You do realize that C and C++ are two different languages?

--
Remove del for email

red floyd

unread,
Apr 20, 2016, 1:41:51 AM4/20/16
to
I have posted a complete solution for you at the following URL:

https://www.cs.rit.edu/~mjh/docs/c++-faq/how-to-post.html#faq-5.2



Öö Tiib

unread,
Apr 20, 2016, 6:07:12 AM4/20/16
to
Perhaps, since it posted that first to comp.lang.c but got
stock replies there.

Öö Tiib

unread,
Apr 20, 2016, 6:14:30 AM4/20/16
to
On Tuesday, 19 April 2016 22:05:13 UTC+3, somurg...@gmail.com wrote:
> 1. Construct your own library by generating .c and .h files.

Should the code generator (that makes described C code) be
written in C++ or may you use some text-oriented language
like Perl or Python?

Christian Gollwitzer

unread,
Apr 21, 2016, 1:35:02 PM4/21/16
to
Am 19.04.16 um 21:04 schrieb somurg...@gmail.com:
> Example user interface should be similar to the following (red entries represent the user inputs):
> Please make a selection with the corresponding number of any operation:
> 1. sumOfIntegersDivisibleBy3
> 2. factorial
> 3. power
> 4. is divisible
> 9. Exit
> 3
> Please enter two integers x and y to calculate x^y
> 2 3
> Result is: 8
> Please make a selection with the corresponding number of any operation:
> 1. sumOfIntegersDivisibleBy3
> 2. factorial
> 3. power

That is a horrible user interface. The user has no possibility to
correct for erroneous input, only by starting over and typing the same
10 digit numbers again.

Good user interfaces are either graphical, where the user can correct
and update the data anytime, or command line option parsing, where the
facilities of the shell are used (history repeating, line editing, file
completion etc. )

Christian

Jorgen Grahn

unread,
Apr 24, 2016, 1:18:24 PM4/24/16
to
On Thu, 2016-04-21, Christian Gollwitzer wrote:
> Am 19.04.16 um 21:04 schrieb somurg...@gmail.com:
>> Example user interface should be similar to the following (red entries represent the user inputs):
>> Please make a selection with the corresponding number of any operation:
>> 1. sumOfIntegersDivisibleBy3
>> 2. factorial
>> 3. power
>> 4. is divisible
>> 9. Exit
>> 3
>> Please enter two integers x and y to calculate x^y
>> 2 3
>> Result is: 8
>> Please make a selection with the corresponding number of any operation:
>> 1. sumOfIntegersDivisibleBy3
>> 2. factorial
>> 3. power
>
> That is a horrible user interface. The user has no possibility to
> correct for erroneous input, only by starting over and typing the same
> 10 digit numbers again.

Yes, and I can't see why it's so common in the kind of exercises
people post for help with. It seems so much easier for teachers to
provide unit tests, and tell the students to make them pass.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
0 new messages