Sunteți pe pagina 1din 12

Experiment #01A: Software Development Principle E01A: PART ONE A2.

.1 Design a C++ program that will calculate and display the voltage across a resistor carrying 3 Ampere. The program enables a user to input the value for resistor via keyboard.

Begin Insert R Set I = 3 Calculated: V = I*R Display V End

A2.2 Design a C++ program to calculate and display n voltage values across two resistor in series using the equation V= I (r1 + r2). The user should provide both resistors values as well as the value of n via keyboard. Assume that the current, I flowing this circuit is 5 Ampere.

Begin Assign I = 5A Assign a= 1 Insert n Do Insert R1 and R2 Calculated: V = I* (R1+R2) Display V While (a<=n) Calculated a= a+1 End

E01A: PART TWO b) Report the output produced by your program. Give your opinion. You may compare your output with the following output window. Program: /*Program description: Find a voltage across a 200 ohm resistor carrying 3A current using Ohm's Law*/ #include<iostream> using namespace std: void main () { int V,I,R; I=3; R=200; V=I*R; cout<<"Voltage across 200 ohm resistor carrying 3A is"<<V<<"V"; }

Output:

Answer: In my opinion, the comparison of the both of the program, it shold be add the \n at the last line to view the statement Press any key to continue /*Program description: Find a voltage across a 200 ohm resistor carrying 3A current using Ohm's Law*/ #include<iostream> using namespace std: void main () { int V,I,R; I=3; R=200; V=I*R; cout<<"Voltage across 200 ohm resistor carrying 3A is "<<V<<"V.\n; }

Output:

c) do reverse engineering by providing the first three (3) steps of software development cycle; requirements specification, analysis and design. These three steps must reflect the provided source code. Calculate the voltage across a 200 ohm resistor carrying 3A using Ohms law. Then display the result. Data input Current, I = 3 Resistance value, R = 200 Data output Voltage, V Formula V = IxR Constrain Nil Using Pseudocode Begin Assign I = 3 Assign R = 200 Calculate V = IxR Display V End

1.

Requirement Specification

2.

Analysis

3.

Design

Experiment #01B: Introduction to C++ Programming E01B: PART ONE Program: /* File name: E01B.cpp File description: Converts distance from miles to kilometers */ #include <iostream> #define KMS_PER_MILE 1.609 using namespace std; int main (void) { double kms; double miles; cout<<"Enter the distance in miles:"; cin>>miles; kms = KMS_PER_MILE + miles; cout<<"That equals"<<kms<<"kilometers.\n"; return 0; }

Questions: a) What type of error occurs during compilation? - The data type double miles didnt have in the program - The spelling off MILES is not same in the program. - Didnt have } symbol at the end the program. b) What are the changes you should do to get zero error (successful compilation)? Give reason for each modification you have made. - The data type double miles should be able to represent the distance of miles. It is because the memory allocated for a value of the double data type is miles - Make sure all the spelling in program were right because it can be the program will be error. - Make sure } symbol were write at the end the program. c) What is the output?

d) Did you get the correct output? - Yes, I get the output.

E01B: PART TWO PS4 Construct a C++ program that calculates and displays the effective inductance (L) of two coils arranged in (i) serial AND (ii) parallel. The user should provide connection of coils, inductance of L1, inductance of L2 and mutual inductance (M). The formula is: Lseries = L1 + L2 + 2M Lparallel = L1 + L2 +M L1 + L2 2M The program displays the result in three points on computer screen. Program: /*File name: E01B.cpp File description: Calculated the effective inductance (L) of two coil arranged in series and parallel*/ #include<iostream> #include<iomanip> #include<cmath> using namespace std; int main (void) { double Lseries; double Lparallel; double L1,L2,M; cout<<"Enter value of L1:"; cin>>L1; cout<<"Enter value of L2:"; cin>>L2; cout<<"Enter value of M:"; cin>>M;

Lseries = L1+L2+2*M; Lparallel = L1+L2+sqrt(M)/(L1+L2-2*M); cout<<"The value of inductance series is "<<fixed<<setprecision (3)<<Lseries<<endl; cout<<"The value of inductance parallel is "<<fixed<<setprecision (3)<<Lparallel<<endl; return 0; }

Output:

S-ar putea să vă placă și