首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导data留学生程序、讲解C/C++编程 调试Matlab程序|讲解R语言编程
项目预算:
开发周期:
发布时间:
要求地区:
Please make sure you have completed Practical 2 before continuing with Practical 3.
Create a new project or file for each question in order to complete the exercises (refer to practical 1 or ask your
supervisor if you are having problems doing so). As seen below, your file should include appropriate comments
consisting of the following – file name, your details, version number and date, brief program description and the
University’s academic misconduct statement. All practical and assignment work you produce in this course
should have the following comments.
/* File: practical03.c
Author: your name
Email Id: your email id
Description: Practical 3 - ...
This is my own work as defined by the University's
Academic Misconduct policy.
*/
Question 1
Properly indent the following statements using the examples in your lecture notes and information found in the
style guide (on course website: 'Additional Resources'->'C Programming Practice'). This
question develops graduate quality 6 by producing work that communicates appropriately with professional
colleagues through source code documentation and demonstrating the capacity to apply international coding
style standards, guidelines and good programming practices.
a)
int a = 1; int b = 1; int c = 1;
if (a == b) { printf("In if statement.\n"); printf("Equal.\n"); } else {
printf("In else statement.\n"); printf("Not equal.\n"); }
The above code should produce the following output:
In if statement.
Equal.
b)
int max = 5;
int count = 0; int k = 0;
while (k < max) {
count = count + 1; printf("In while loop.\n");
k = k + 1; } printf("Count is: %d\n", count);
The above code should produce the following output:
In while loop.
In while loop.
In while loop.
In while loop.
In while loop.
Count is: 5
c)
int k;
for (k = 0; k < 5; k++) {
printf("In for loop.\n");
printf("%d\n",k);
}
The above code should produce the following output:
In for loop.
0
In for loop.
1
In for loop.
2
In for loop.
3
In for loop.
4
Question 2
What is the output produced by the following code? You may check your results by entering the programs into
Microsoft Visual Studio.
a)
int k = 1;
while (k <= 5) {
printf("Stuck in a loop!\n");
k = k + 1;
}
printf("okay then...\n");
b)
int k = 6;
while (k >= 2) {
printf("Still looping.\n");
k = k - 2;
}
c)
int num1 = 2;
int num2 = 4;
if (num1 < num2)
printf("Yes.\n");
d)
int mark = 78;
if (mark >= 85)
printf("HD");
else if (mark >= 75)
printf("D");
else if (mark >= 65)
printf("C");
else if (mark >= 55)
printf("P1");
else if (mark >= 50)
printf("P2");
else if (mark >= 40)
printf("F1");
else
printf("F2");
e)
int k;
for (k =0; k < 4; k++)
printf("%d\n", k);
f)
int k;
for (k = 0; k < 10; k+=2)
printf("k is: %d\n", k);
Question 3
The area of a circle is calculated as follows: area = PI * (radius * radius). Write a program that prompts the user
to enter a radius, calculates the area of a circle and displays the area to the screen (with appropriate text). Refer
to practical 1 solution if you are needing help with this exercise. Create a file in order to complete this exercise.
Question 4
Write a program that asks the user for the number of males and the number of females enrolled in your practical
class. The program should display the percentage of males and females in the class. (Hint: suppose there are 8
males and 12 females in a class. There are 20 students in the class. The percentage of males can be calculated as
8 / 20 = 0.4 or 40%. The percentage of females can be calculated as 12 / 20 = 0.6 or 60%. (Modified: Gaddis,
Tony. Programming Exercises, Chapter 2).
Question 5
Write a program that prompts the user enter a price (dollar amount) and a percentage discount. Calculate and
display the new price with discount. Your output should be presented as follows (user input appears in bold to
differentiate it from text that is displayed to the screen by the program):
Example 1:
Please enter price in dollars: 100.00
Please enter percent discount: 0.25
Price with discount is: 75.0
Example 2:
Please enter price in dollars: 25.0
Please enter percent discount: 0.10
Price with discount is: 22.5
Question 6
Write a program that prompts the user to enter a temperature. If the temperature is greater than or equal to 40
degrees, display the message 'Way too hot – stay inside!', if the temperature is greater than or equal to 30
degrees, display the message 'Hot – beach time!', if the temperature is greater than or equal to 20 degrees,
display the message 'Lovely day – how about a picnic!?!', if the temperature is greater than or equal to 10
degrees, display the message 'On the cold side – better take a jacket!', if the temperature is less than 10 degrees,
display the message 'Way too cold – stoke up the fire!'. Hint: you will need to use an if statement to do this.
Checkpoint: Please make sure your supervisor sees your work so far.
Question 7
Write a program that prompts the user to enter a number within the range of 1 through 10. The program should
display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the
program should display an error message. The following table shows the Roman numerals for the numbers 1
through 10. (Modified: Gaddis, Tony. Programming Exercises, Chapter 4).
Number Roman Numeral
1 I
2 II
3 III
4 IV
5 V
6 VI
7 VII
8 VII
9 IX
10 X
Your output should be presented as follows (user input appears in bold):
Enter an integer from 1-10: 7
VII
Question 8
The date 10 June 1960, is special because when it is written in the following format, the day times the month
equals the year:
10/6/60
Write a program that asks the user to enter a day, a month (in numeric form), and a two-digit year. The program
should then determine whether the day times the month equals the year. If so, it should display a message
saying the date is magic. Otherwise, it should display a message saying the date is not magic.
(Modified: Gaddis, Tony. Programming Exercises, Chapter 4).
Your output should be presented as follows (user input appears in bold):
Enter the day of month: 10
Enter the month in numeric form: 6
Enter the year in two digit format: 60
The date 10/6/60 is a magic date.
Checkpoint: Please make sure your supervisor sees your work so far.
Question 9
This question builds on the program written in an earlier practical and presented in your lecture slides.
Write a program to generate a random number between 1 –10.
Display the random number to the screen as follows:
Random number is: 7
Modify your program so that it asks (prompts) the user to guess the random number.
Display the user’s guess to the screen.
Modify your program so that it displays ‘Well done –you guessed it!’ if the user guesses the number
correctly, displays ‘Too low’ if the guess is lower than the random number, and displays ‘Too high’ if the
guess is higher than the random number.
Add a while loop which allows the user to keep guessing until they guess the correct number.
You may use the solution presented in the lecture slides in order to complete this exercise.
Modify the above program as follows:
a. Generate a random number between 1-100 (instead of 1-10).
b. Add another while loop to ask the user whether they wish to play again (hint: you will need to nest while
loops to get this to work). Refer to the following algorithm for help with this (an algorithm is a set of
steps describing how you would solve a problem – it is written in simple English and provided to help you
solve this problem):
set variable play = ‘y’
WHILE play == ‘y’
generate a random number
prompt for and read user’s guess
WHILE user’s guess is not equal to random number
IF guess < number
Display – ‘'Too low – please try again!'
ELSE
Display – ‘'Too high – please try again!'
prompt for and read user’s guess
prompt whether user would like to play again
Please note: the provided algorithm above is not C code. It has been provided in order to assist you with
solving this problem. Using the algorithm provided, helps you think less about the steps needed in order
to solve the problem, and more about how you would write it in the C programming language.
A note on reading characters:
The scanf function behaves differently when the %c format specifier is used from when the %d conversion
specifier is used. When the %d conversion specifier is used, white space characters (blanks, tabs or newlines, etc)
are skipped until an integer is found. However, when the %c conversion specifier is used, white space is not
skipped, the next character, white space or not, is read. You may find that this causes your loops to 'skip' the
prompt and not provide you with an opportunity to enter a character at the prompt.
Continued on the next page…
A note on reading characters (continued…):
To fix this, leave a space before the %c as seen in the following scanf statement.
scanf(" %c", &response);
For example:
#include
int main() {
char playAgain = 'y';
while (playAgain == 'y') {
printf("\n\nDo stuff... : )\n\n");
/* space before %c skips white-space characters such as newline */
printf("Play again [y|n]? ");
scanf(" %c", &playAgain);
}
return 0;
}
Make sure your work adheres to the guidelines presented in the C Programming Practice and lecture slides. Make
sure your code is correctly indented and contains comments in order to correctly describe its use. Doing so will
develop graduate quality 6 (use of communication skills) by producing source code that has been properly
formatted, and by writing adequate, concise and clear comments.
Checkpoint: Please make sure your supervisor sees both your program output and code.
Question 10
Write a program that will read numbers until the user enters a negative number. Display the number of values
entered and the largest value entered. Do not use an array for this exercise. (Hint: use a while loop with a nested
if statement to do this).
Question 11
When a part is manufactured, the dimensions are usually specified with a tolerance. Assume that a certain part
needs to be 5.4 cm long, plus or minus 0.1 cm (5.4 ± 0.1 cm). Write a program that prompts for the dimension
and determines whether a part is within these specifications. The program should read dimensions until the user
enters a dimension of zero. (Hint: use a while loop with a nested if statement to do this).
Checkpoint: Please make sure your supervisor sees both your program output and code.
Please make sure you save and keep all of your practical and assignment work. Please ask your supervisor if
you are having difficulties doing so.
End of practical 3.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!