讲解screen shots、辅导C/C++编程、讲解Circuit、辅导C/C++语言
- 首页 >> C/C++编程Deadline: 22-Nov, Total mark: 10% of the module’s mark
The assignment has two parts, every part has 5% of the total module’s mark. Please submit
a report containing both Part-1 and Part-2. Both parts should include a brief program
description, design, coding and testing (screen shots), and finally the documentation (user
manual). Your combined report should not exceed 10 A4 pages (font size>11) excluding the
source code. Source code with proper comments must be included as appendix.
Your report should have two parts and each should consist of:
1. Introduction (nature of the problem and what you are asked to do).
2. Description of your program design and structure. For example, what are the input
data and what do you want the program to output? Does the programme give a user
clear instruction when the programme starts? What type of logical structure is used
and what are the conditions used in the logical structure?
3. Typical results: screen shots should be included.
4. A brief description of how to run your program and how to interpret the results.
Discussion of the performance of your program and coding problems that you have
encountered.
5. Appendix: source code (please also keep an exact copy of your submitted
project/source code in your M:Driver). Remember to add sufficient comment to the
code so others could understand easily what each section of the code does. If the
code is difficult to read, marks will be deducted.
Part-1: A Non-linear Circuit Problem (5%)
In this exercise you are required to write a computer program which will calculate the
voltage across the resistor RL in the following circuit:
where V0 = 0.26 V and RL=150kΩ. For this exercise, we will assume that the special
semiconductor diode used in the circuit has a current-voltage characteristic given by:
0
1
eVD
(1)
Where i is the diode current and VD the voltage across the diode. e/kT= 40 at room
temperature and
8
0
I 8 10
A. The normal threshold voltage drop of 0.7 V before the
diode starts to conduct any electric current does not apply in this exercise.
Using your programme you need to present in your report two sets of results: the voltage
drop across RL for e/kT= 40 and e/kT= 20. Your program should be designed in such a way
that V0, RL and e/kT are read from keyboard with sufficient information displayed to the user
before an input is taken. Appropriate output to the screen should also be generated to
display the calculated results.
Hint: Since the current going through the resistor is the same as that passing the diode, the
voltage across the diode VD is determined by the following equation:
(2)
Where i is the current in the circuit. Read the background text below and try to understand
how the Newton-Raphson's method can be applied to solve this equation.
Background: Equation (2) is a nonlinear-equation, to solve it for VD a numerical method has
to be implemented. A powerful method to solve such nonlinear equations is the NewtonRaphson's
method. To use this method all terms of the nonlinear equation has to be moved
to the left, such that the right hand side is 0. The left hand side is called F(x):
(3)
Where the variable to be solved for VD, is now called x. To solve the equation, one starts
with an initial guess x0, then use the following equation to improve the initial guess:
(4)
Where F’(xi) is the derivative of F(x) with respect to x. Equation (4) is solved iteratively,
which means starting from x0 (the initial guess), calculate x1, then use x1 to calculate x2, and
so on. This iterative process must continue until the following condition is satisfied:
(5)
where is a number set by the user to determine the accuracy of the solution. By choosing = 10-4
, the solution x is accurate up to the 5th significant digit. Please use that value for in
your program.
The part of your program code which deals with the iterative process will be repeatedly
executed. You should avoid an infinite loop. For example, an infinite loop (never ending
loop) will result if your two successive solutions never satisfy the accuracy requirement. This
can be caused by the error in your program and/or by extremely slow convergence. You
need therefore to monitor the progress of the iterative process and stop the process if you
find that further iteration will not lead to a solution. Think how this could be practically
implemented in your program.
Part-2 Programming exercise (5%)
Write a program that reads from the keyboard the name (Given name + space + family
name) of 5 persons and writes them to a file in a known folder. Each name in the file always
starts on a new line. Note that you need consider the case where a person has three or more
name parts (e.g., Given, Middle and Family) in order to get full marks. You also need
check/change the first letter of the names into upper case.
What you need to do is to write a C++ program which:
1. Displays a message on the screen such as “Name number xx is saved” where xx is the
number of the name in the list (Hint: use for loop).
2. Displays a message on the screen stating where the file is saved.
Compile, link and run the programme (i.e. create an exe file, which is done automatically in
visual studio). Remember to add sufficient comments in your code.