首页 > > 详细

Software编程讲解、辅导c/c++程序、C++编程辅导 辅导留学生 Statistics统计、回归、迭代|辅导Python编程

项目预算:   开发周期:  发布时间:   要求地区:
Class Test: Software Questions
Please answer all five questions below in the spaces provided in this file. Each question is
worth different marks, giving a total mark out of 15 for this part of the class test. Upload your
solution to the Learn Dropbox by 4pm on Thu 4th March.
1. Write one C instruction to declare and initialise an array of 7 structures following structure
template below.
struct day
{
char name[10];
int type;
};
Name this array as week and initialise it with the names of 7 days from Monday to Sunday,
and the type of day, i.e. 1 for a workday and 0 for a weekend day. (2 marks)
Answer:
2. Write a function prototype for the following, a function named mix, which accepts three arguments.
The first argument should accept an integer, the second a floating point number and the third a
character. The function returns no value. (1 marks)
Answer:
3. Write a number in the shaded area of the program below to get 0.50 printed. (3 marks)
#include
int main(void)
{
float num;
num = 1 / ;
printf("%.2f\n", num);
return 0;
}
4. The circuit on the right shows the initial voltage across the capacitor
is V0, which remains constant until the switch is closed at time t = 0,
afterwards the capacitor is discharged. The voltage, V(t), across the
capacitor is given by the equation
𝑉(𝑡) = 𝑉0𝑒
(−𝑡⁄𝑅𝐶)
where R is the resistance, C is the capacitance and t is time. Assuming V0 = 24 V, R = 4000 Ω and
C = 5000 μF. Complete the missing code in the square to plot the voltage across the capacitor from
t= 0 s to t = 50 s, in increment of 2 seconds. Program output should look like the chart below. The
horizontal axis represents voltage and the vertical axis represents time. You can expand the square
as you need. (3 marks)

/* Plot the voltage across the capacitor from t = 0s to t = 50s, in
increment of 2 seconds */
#include
#include
#define V0 24
#define R 4000.0
#define C 0.005 /* the unit is F not μF */
int main(void)
{
int t, V;
char label[]=" V axis ";
char axis[]="+---------------------------------------------->";
char line[]="| ";
printf("%s\n",label); /* use control sequence %s for string */
printf("%s\n",axis);
for (t = 0; t <= 50; t+=2)
{
}
return 0;
}
Also, can you explain why the curve is not very smooth? (1 marks)
Answer:
5. Almost all curves (unless tangential to x-axis) exhibit a change in
sign of y on passing through a root. The program below finds root of
equation y = x
4
- 3x
3 + 2x
2
- 5x – 20 between -10 and 10 as shown in
the figure on the right, if two values of y differ in sign (y1 * y2 < 0),
An actual root must exist between x and x+Δx. Linear interpolated
root (xr) is taken as an interpolated root. Smaller increment Δx is,
closer interpolated root and actual root are. Complete the program
below by filling the missing code in the squares to print to any
interpolated root. You can expand the square as you need.
(5 marks)
/* Finding root with fixed increment iteration */
#include
#include
#define INCR 0.01 /* increment 0.01 */
int main(void)
{
float x, x1, x2, y1, y2, xr;
float fun(float); /* function prototype */
for ( x = -10.0; x <= 10.0; x += INCR)
{
x1 = x;
x2 = x + INCR;
y1 = fun(x1); /* evaluate the function for x1 */
y2 = fun(x2); /* evaluate the function for x2 */
if (y1 * y2 < 0) /* test for change of sign */
{
}
}
return 0;
}
float fun(float x) /* Evaluates algebra function of x */
{
}

软件开发、广告设计客服
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 9951568
© 2021 www.rj363.com
软件定制开发网!