Sunteți pe pagina 1din 75

UNIVERSITI TUN HUSSEIN ONN MALAYSIA

FACULTY OF ELECTRICAL AND ELECTRONIC ENGINEERING

Group Assignment
FINAL REPORT
DEVELOPING TEACHING AND LEARNING SYSTEM IN
ELECTRIC CIRCUIT ANALYSIS

2
SEMESTER 2 (2007/2008)

NAMA PENSYARAH: PUAN ZARINA BINTI TUKIRAN

NAMA NO MATRIK
SOO CHAN CHUAN AE070264
FADHULLAH BIN AMINUDDIN AE070119
CALVIN TAN KWANG YUEN AE070254
MOHAMAD IDHAM BIN IDRIS CHANDRAN AE070122
MOHD FARHAN BIN ISMAIL AE070103
MUHAMMAD AFIQ BIN BAHRUDIN AE070150
THEN KAI HAO AE070243
MUHAMAD ANNAS BIN ABDULLAH AE070114

CONTENT
1. Introduction 3

2. Company Background 4

3. Organization and Responsibilities 6

3.1. Organization Chart 6

3.2. Responsibilities 7

4. Problem Analysis 8

5. Flow Chart 14

6. Coding 23

7. Output & Testing 54

8. Advantages 64

9. Recommendations 66

10. Conclusion 67

11. Bibliography 68

3
12. Appendix 69

1. INTRODUCTION

Nowadays computers are used for problem solving in almost all of our daily
activities like bill payments, booking transportation tickets, communication services,
e-mailing friends and many more. Computer programs also have been embedded in
various electrical and electronic devices
Therefore, our Company SilveriuM™ have prepared a proposal and would
like to join the tender project of developing teaching and learning system in electrical
circuit analysis for the Faculty of Electrical and Electronic Engineer, UTHM.
In this project, we need to develop a system that is capable to perform several
tasks and in this proposal, our company has fulfilled all the requirements and criteria
that the Faculty of Electrical and Electronic Engineer have requested. We have come
up with the best program in fulfilling the requirement that the teaching and learning
system needed.
There are five problem statements which are related to electric circuit analysis
that have been given to us to solve it in order to develop a teaching and learning
system in electric circuit analysis . We begin the proposal by identifying the problem
requirement of the task that has been given to us. When we have identified the

4
problem requirement, we proceed to analyzing the problem. When these first two
steps are done, then only we move on to designing the program.

2. COMPANY BACKGROUND

Company Name : SilveriuM ™


Location :
No 7, Jalan Betik, Taman Maju, Parit Raja, 86400 Batu Pahat, Johor.

5
Background :
SilveriuM™ was established on September 21 of 2003. The founder of the
company is Mr. Then Kai Hao and his partner is Mr. Fadhullah Bin Aminuddin and
Mr. Calvin Tan Kwang Yuen. Now the company is well established and it has been
going on for 4 years. To contact our company, the details are listed below:
Office number : 07-4015836 (Hotline)
Fax number : 07-4015836
E-mail: webmaster@silverium.com
Website: http://www.silverium.com

Mission
Our mission is to enhance and solve problem by using computer program.
Therefore, we target to develop a program that is capable to solve any problem that is
required to solve. In order to do this, our company SilveriuM™ endeavors to:
 Offer best-in-class service quality through design and develop computer
program

 Leverage a software-enabled platform to quickly adapt its services to new


technologies and stay ahead of customer needs

 Interoperate with today's and tomorrow's programming system and solutions

 Ensure that only "protected" devices get the program and the identities and
data sessions are secured

 Give enterprise IT control over and visibility into connection cost,


performance, and security

 Maintain a simple user experience even as connectivity options and security


requirements grow in complexity

Vision
SilveriuM™ envisions a world where all people are able to solve their
problem using computer programs. In order to do that, we are promoting the benefit
of using computer programs to solve problems to all beginner users. Besides that,

6
SilveriuM™ also tends to give off great discount rate for the first time customer to
promote computer programming, helping those who really need it.

3. ORGANIZATION AND
RESPONSIBILITIES
Organization Chart

7
PROJECT MANAGER
THEN KAI HAO

SYSTEM ANALYST
SOO CHAN CHUAN

PROGRAMMER
MOHAMMAD AFIQ BIN BAHRUDIN
FADHULLAH BIN AMINUDDIN
CALVIN TAN KWANG YUEN
MOHD FARHAN BIN ISMAIL

MARKETING OFFICER

MOHAMAD IDHAM BIN IDRIS CHANDRAN


MOHD ANNAS BIN ABDULLAH

Responsibilities

Project Manager: Then Kai Hao

The work of a project manager is to supervise and consult the whole team in doing
this project. The project manager is also involved in doing the programming part in
this project

System Analyst: Soo Chan Chuan

8
Meanwhile system analyst is responsible for doing research, planning and
recommending software and system choices to meet an organization business
requirements. Besides that, he is responsible to develop cost analysis, design
considerations, and implementation time-lines. Other then that, he needs to be
responsible for feasibility studies of a computer system before making
recommendations to senior management.

Programmer: 1) Mohammad Afiq Bin Bahrudin


2) Fahdullah Bin Aminuddin
3) Calvin Tan Kwang Yuen
4) Mohd Farhan Bin Ismail

The work of a programmer is to design and write a program that is capable of solving
the task that is given. Besides that, they also need to test and debug the program that
they have created. This is to make sure that the program can run smoothly. If
necessary, they also need to debug the program for the second time to confirm the
program is fully functioned.

Marketing Officer: 1) Mohamad Idham Bin Idris Chandran


2) Mohd Annas Bin Abdullah

Marketing officer is in charge of promoting the system that has been created as a
product. Besides that, they need to know and explain briefly about how the system
works. On the other hand, they are also in charge in the marketing research and
customer services.

4. Problem Analysis
Problem Statement 1

Develop a system to calculate the equivalent capacitance for n number of capacitor in


connection of series and parallel

Step 1: Problem requirement

Develop a system to calculate the equivalent capacitance for number of capacitor in


connection of series and parallel.

9
Step 2: Analysis

Determine what is required to do:


 To calculate value of equivalent capacitance in connection of series and
parallel
Based from statement user must put number of capacitor mean n and value
of each capacitor.
To determine the equivalent capacitance in connection of series and
parallel, use equivalent capacitance parallel. The number of capacitor and
value of each capacitor must be in positive value.
Therefore:

 The problem input is number of capacitor means n and value of each capacitor.

 The problem output is value equivalent in connection of series and parallel.

Data Requirement and Relevant Formula are listed below:

 Problem input

 Total_num /*represent the number of capacitor*/

 X /*Value of each capacitor*/

 Problem output

 Value of equivalent in connection of series and parallel

 Constraint
 The program will not calculate the equivalent capacitance if
user put a non positive value for the total capacitor and value of
each capacitor. The program should prompt the user to reinsert
the data.

 Relevant Formula

 capacitance_series=1/(1/capacitance_series+1/x)

 capacitance_parallel=capacitance_parallel+x

10
Problem Statement 2

Ohms Law states that the voltage v across a resistor is directly proportional to the
current i flowing through the resistor. Resistor in an element used to model the
current-resisting behavior and it is usually made from metallic alloys and carbon
compounds. On the other hand, resistance (R) defined as a physical property or ability
to resist current, behavior of resisting the flow of electric charge as shown in Figure
Task 2. Develop a system to verify the relation in between cross-sectional area (A),
length (l) and resistivity (p).

Length, l
Cross sectional area, A

Material with resistivity, p

Step 1: Problem requirement

Develop a program to verify the relation in between cross-sectional area (A), length
(l) and resistivity (p).

Step 2: Analysis

Determine what is required to do:


 Obtain resistance (R), length (l), cross sectional area (A) and resistivity
(p).
 Verify the relation in between cross-sectional area (A), length (l) and
resistivity (p).

Therefore:
 The problem input is resistance (R), length (l), cross sectional area (A)
and resistivity (p).
 The problem output is the relation between resistance(R0 with
resistivity(p), length(l), and cross sectional area(A).

11
The data requirements and relevant formulas are listed below:

 Problem input:
R, l, A, p, /*represents resistance (R), length (l), cross sectional
area (A) and resistivity (p)*/

 Problem output:
Relationship between resistance(R) with Resistivity(p), Cross-sectional
Area(A) and Length(l)

 Relevant formula:
R= (p* l)/ A
k1=l/a
k2=p/a
k3=p*l
R=p*k1
R=l*k2
R=k3/A

 Constrain:
I. The program will not run if the selection to find relation of resistance
with resistivity, length and cross-sectional area is invalid.
II. If the input value is character the program will not run.

12
Problem Statement 3

Consider the following circuit in Figure Task 3. Develop a system to find the value of
v(t) and i(t) for time interval of 0 to 10 second

i(t) 5Ω

+
VS = 10 cos 4t v 0.1F

Step 1: Problem Requirement

Design a system or program that is able to calculate the values of v(t) and i(t) for time
interval of 0 to 10 seconds for the circuit below.

Step 2: Analysis

Determine what is required to do:


 To calculate the value for v(t) and i(t) for the circuit.

Therefore:
 The problem input is the given value for Vs = 10cos4t, R = 5 Ω and c = 0.1F
in the question.
 The problem output is the value of v(t) and i(t) for time interval of 0 to 10
seconds

The data requirements and relevant formulas are listed below:

 Problem Input:
The given value for Vs = 10cos4t, R = 5 Ω and c = 0.1F

 Problem Output:
Value of v(t) and i(t) for the time interval

 Relevant Formula:
v(t) = (10 cos ( 4t X ( π/180)))
i(t) = (10 cos ( 4t X (π/180))) / (3.2 cos ((4t + 51.34) X (π/180)))

 Constrain:
The constrain of this program is that it can only calculate the value of v(t) and
i(t) for the circuit that is given by the question with a fix value of Vs =
10cos4t, R = 5 Ω and c = 0.1F

13
Problem Statement 4

You are required to develop a glossary that contains at least five terms related with
electrical circuit theory and electrical technology field. Your system must be able to
add, update/edit and display the glossary.

Step 1: Problem Requirement

Develop a program that contains at least five terms related with electrical circuit
theory and electrical technology field. The program is also able to add, update/edit
and display the glossary.

Step 2: Analysis

Determine what is required to do:


 Develop a glossary that contains at least five term related with electric circuit
theory and electric technology field.
 The program that is develop must be add, update and editable.
 Then display the glossary.

Therefore:
 The problem input is input purpose
 The problem output is glossary

The data requirements and relevant formulas are listed below:

 Problem input:
Input purpose

 Problem output:
Add glossary, edit/update glossary or display glossary

 Constraint :
This program will not show the terms automatically once this program is
executed and the user has to key in the data first before they can view the
glossary entered.

 Relevant formula:
None

14
Problem Statement 5

You are required to develop a true/false quiz that consists of twenty five questions.
Your system must be able to show only 5 random questions at a time. The entire
user’s mark must be recorded on text file.

Step 1: Problem Requirement

Develop a program that develops a true/false quiz that consists of twenty five
questions. The program must be able to show only 5 random questions at time.
Besides that, the entire user’s mark must be recorded on text file.

Step 2: Analysis

Determine what is required to do:


 Based on statement, we needed to develop program that can determine True or
false quiz which is 25 questions.
 We also need to show 5 random questions at a time.

Therefore:
The problem input is student info and answer from user(yes or no)
The problem output is display student info, result and save file mark.

The data requirement and relevant formula are listed below:

 Problem input
(i) Student Info
(ii) Answer(yes or no) /*represent the answer for the question*/

 Problem output
Display student info, result and save file mark.

 Relevant formula
None

 Constrain
The randomly selected question can be repeated, which mean the same
question can be ask again at a time.

15
5. Flow Chart
Problem Statement 1: Flow Chart

16
Begin

Counter =1
Capacitance_parallel = 0.0

Read
Total_capacitor

no
Total_capacitor >0

yes

yes
Read value
Counter<=total_capacitor
of capacitor

no

Print value
no
of
capacitance
Capacitor>0
equivalent

yes

capacitance_series=1/(1/capacitance_series+1/x);

capacitance_parallel=capacitance_parallel+x;

End

counter = counter + 1

Problem Statement 2: Flow Chart

17
18
19
20
21
Problem Statement 3: Flow Chart

Begin
A

Start
Print This program will
calculate the value for
v(t)
i(t)
for time interval 0 to
10 seconds for a No
While
circuit. (t <= 10) End
Given that a series circuit
that have the value of
Vs= 10cos4t, R= 5 ohm
and c= 0.1F. Yes

v(t) = 10*cos((4*t)*(pi/180))

i(t) =
Calculate the value (10*cos((4*t)*(pi/180))) /
for v(t) and i(t) for (3.2*cos
the time interval 0 ((4*t+51.34)*(pi/180)))
to 10 seconds

A
Print value of
v(t) and i(t)

End

22
Problem Statement 4: Flow Chart

23
Problem Statement 5: Flow Chart

24
B

R<5

CALCULATE
MARK.
MARK=(RIGHT/
RIGHT+WRONG)

GET
STUDENT
CHOICE

BEGIN==0

RETURN

25
6. Coding
Problem Statement 1: Coding

#include<stdio.h>
void main()
{
int total_num,counter =1;
double capacitance_series,capacitance_parallel;
double x;

int jawapan;

capacitance_parallel=0.0;
capacitance_series;

printf("############################################################
###################\n\n");
printf("\n\t\t\t ~///~\n\t\tWelcome to our program \n");
printf("\n\t\tThe simple program with 2 steps\n");
printf("\nThis program were provide to calculate the equivalent
capacitance\n");
printf("\nStep 1 : enter how many capacitor that you have in circuit\n");
printf("\nStep 2 : enter the value for each capacitor\n");
printf("\nStep 3 : done!\n\n");
printf("\nATTENTION PLEASE !!! --> PUT THE POSITIVE VALUE
ONLY\n\n");

printf("############################################################
###################\n\n");

do
{

do
{

printf("\nEnter total capacitor that you have in circuit :");


scanf("%d",&total_num);
if(total_num<=0)
printf("\n\t\tREINSERT DATA.\n\tYOUR DATA SHOULD BE
GREATER THAN ZERO\n\n");
}
while(total_num<=0);

while(total_num>0)

26
{

do
{
printf("\n\t->Enter value for each capacitor = ");
scanf("%lf",&x);
if(x<=0)
printf("\n\t\tREINSERT DATA.\n\tYOUR DATA SHOULD
BE GREATER THAN ZERO\n\n");
}
while(x<=0);

capacitance_series=1/(1/capacitance_series+1/x);
capacitance_parallel=capacitance_parallel+x;
total_num--;

}
printf("\n->Capacitance in series :->\t%.2f\n",capacitance_series);
printf("->Capacitance in parallel:->\t%.2f\n\n",capacitance_parallel);

printf("Do you want to continue?\n\nIf yes press 1.If no press 2 = ");


scanf("%d",&jawapan);

}
while(jawapan == 1);

27
Problem Statement 2: Coding

#include<stdio.h>
#include <stdlib.h>
void r_p(double k1);
void r_l(double k2);
void r_a(double k3);
void main()
{
double a,l,p,k1,k2,k3;
int counter=1;
int h;

printf("Enter cross-sectional area(A) value:");


scanf("%lf",&a);
printf("Enter length(l) value:");
scanf("%lf",&l);
printf("Enter resistivity(p) value:");
scanf("%lf",&p);
k1=l/a;
k2=p/a;
k3=p*l;

while (counter>=1)
{
printf("\nEnter \n(1)for relation R and p,\n(2)for relation R and
l,\n(3)for relation R and A:");
scanf("%d",&h);
switch(h)
{
case 1:
r_p(k1);
break;
case 2:
r_l(k2);
break;
case 3:
r_a(k3);
break;
}
}
}

void r_p(double k1)


{
double r1,r2,r3,p1,p2,p3;
char Answer;
int counter=1;

28
printf("\nThe k value is %.2f\n",k1);
do
{
printf("Enter resistivity(p1):");
scanf("%lf",&p1);
r1=p1*k1;
printf("Enter resistivity(p2):");
scanf("%lf",&p2);
r2=p2*k1;
printf("Enter resistivity(p3):");
scanf("%lf",&p3);
r3=p3*k1;

printf("\nWhen the resistivity is %.2f, the resistance is


%.2f.",p1,r1);
printf("\nWhen the resistivity is %.2f, the resistance is
%.2f.",p2,r2);
printf("\nWhen the resistivity is %.2f, the resistance is
%.2f.",p3,r3);

if(r1>r2&&r2>r3&&p1>p2&&p2>p3||
r1>r3&&r3>r2&&p1>p3&&p3>p2||r2>r1&&r1>r3&&p2>p1&&p1>p3||
r2>r3&&r3>r2&&p2>p3&&p3>p2||r3>r1&&r1>r2&&p3>p1&&p1>p2||
r3>r2&&r2>r1&&p3>p2&&p2>p1)
{
printf("\n\nWhen resistivity(p) increases, resistance(R) will
increases.\n");
printf("Therefore, resistivity(p) is proportional to
risistance(R).\n");
}
else
{
printf("\n\nError! There are two or three resistivity entered
are same value!\n");
printf("Please reinsert resistivity(p) with different
values.\n\n");
}

}while((r1==r2)||(r2==r3)||(r3==r1));
printf("\nDo you wish to continue verify the relation?(Y or
N): ");
scanf("%s",&Answer);
if ((Answer=='Y')||(Answer=='y'))
counter=1;
else
exit(1);

29
}

void r_l(double k2)


{
double r1,r2,r3,l1,l2,l3;
int counter=1;
char Answer;
printf("\nThe k value is %.2f\n",k2);

do
{
printf("Enter length1(l1) value:",l1);
scanf("%lf",&l1);
r1=l1*k2;
printf("Enter length2(l2) value:",l2);
scanf("%lf",&l2);
r2=l2*k2;
printf("Enter length3(l3) value:",l3);
scanf("%lf",&l3);
r3=l3*k2;

printf("\nWhen the length is %.2f, the resistance is %.2f.",l1,r1);


printf("\nWhen the length is %.2f, the resistance is %.2f.",l2,r2);
printf("\nWhen the length is %.2f, the resistance is %.2f.",l3,r3);

if(r1>r2&&r2>r3&&l1>l2&&l2>l3||r1>r3&&r3>r2&&l1>l3&&l3>l2||
r2>r1&&r1>r3&&l2>l1&&l1>l3||r2>r3&&r3>r2&&l2>l3&&l3>l2||
r3>r1&&r1>r2&&l3>l1&&l1>l2||r3>r2&&r2>r1&&l3>l2&&l2>l1)
{
printf("\n\nWhen length(l) increases, resistance(R) will
increases.\n");
printf("Therefore, length(l) is proportional to resistance(R).\n");
}
else
{
printf("\n\nError! There are two or three length entered are same
value!\n");
printf("Please reinsert length(l) with different values.\n\n");
}

}
while((l1==l2)||(l2==l3)||(l3==l1));
printf("\nDo you wish to continue verify the relation?(Y or
N): ");
scanf("%s",&Answer);
if ((Answer=='Y')||(Answer=='y'))
counter=1;
else
exit(1);

30
}
void r_a(double k3)
{
double r1,r2,r3,a1,a2,a3;
int counter=1;
char Answer;
printf("\nThe k value is %.2f\n",k3);

do
{
printf("Enter area1(A1) value:",a1);
scanf("%lf",&a1);
r1=k3/a1;
printf("Enter area2(A2) value:",a2);
scanf("%lf",&a2);
r2=k3/a2;
printf("Enter area3(A3) value:",a3);
scanf("%lf",&a3);
r3=k3/a3;

printf("\nWhen the area is %.2f, the resistance is %.2f.",a1,r1);


printf("\nWhen the area is %.2f, the resistance is %.2f.",a2,r2);
printf("\nWhen the area is %.2f, the resistance is %.2f.",a3,r3);

if(r1>r2&&r2>r3&&a1<a2&&a2<a3||
r1>r3&&r3>r2&&a1<a3&&a3<a2||r2>r1&&r1>r3&&a2<a1&&a1<a3||
r2>r3&&r3>r2&&a2<a3&&a3<a2||r3>r1&&r1>r2&&a3<a1&&a1<a2||
r3>r2&&r2>r1&&a3<a2&&a2<a1)
{
printf("\n\nWhen area(A) increases, resistance(R) will
decreases.\n");
printf("Therefore, area(A) is inversely proportional to
resistance(R).\n");
}
else
{
printf("\n\nThere are two or three area(A) entered are same
value.\n");
printf("Please reinsert the area(A) with different
value.\n\n");
}
}
while((a1==a2)||(a2==a3)||(a3==a1));
printf("\nDo you wish to continue verify the relation?(Y or
N): ");
scanf("%s",&Answer);
if ((Answer=='Y')||(Answer=='y'))
counter=1;
else
exit(1);

31
}

Problem Statement 3: Coding

#include<stdio.h>
#include<math.h>
#define pi 3.14159

void calculation(void);

main()
{

printf("\nThis program will calculate the value for\n(i) v(t)\n(ii)


i(t)\nfor time interval 0 to 10 seconds for a circuit.");
printf("\nGiven that a series circuit that have the value of Vs= 10cos4t, R=
5 ohm\nand c= 0.1F.\n");

calculation();

void calculation (void)


{
double v,c;
int t;
t=0;

printf("\n\nThe value for v(t) and i(t) for time interval 0 to 10


seconds is:");
while(t<=10)
{
v = 10*cos((4*t)*(pi/180));
c = (10*cos((4*t)*(pi/180)))/(3.2*cos
((4*t+51.34)*(pi/180)));
printf("\nWhen t=%d\tv(t)=%.2lf\ti(t)=%.2lf\n",t,v,c);
t++;
}
}

32
Problem Statement 4: Coding

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

FILE*glo;
int address;
int counter=1;
char selection;
int *num=&address;
char mod[20];
char choose;

struct program
{
char term[50];
char des[150];
}words[100];

void add(void);
void edit(void);
void display(void);

void main()
{

while (counter==1)
{
printf("\nPlease hit A to enter a new term.");
printf("\nPlease hit B to edit or update term.");
printf("\nPlease hit C to display the term.");
printf("\nPlease hit D to exit the program.\n");
scanf("%c",&selection);

switch(selection)
{
case 'A':
add();
break;

33
case 'B':
edit();
break;

case 'C':
display();
break;

case 'D':
printf("Program terminating,...");
exit(1);
break;

void add(void)
{

printf("Please key in the number of terms to be entered.");


scanf("%d",num);
fflush(stdin);
for(int i=0;i<*num;i++)
{
printf("Please key in term#%i: ",i+1);
gets(words[i].term);
printf("Please key in the '%s' description: ",words[i].term);
gets(words[i].des);
fflush(stdin);
}

glo=fopen("test.txt","a");

for( i=0;i<*num;i++)
{
fputs(words[i].term,glo);
fputs("\t",glo);
fputs(words[i].des,glo);
fputs("\n",glo);
}
fclose(glo);

void edit(void)
{

34
glo=fopen("test.txt","r");
for(int i=0;i<100;i++)
{
fscanf(glo,"%s",words[i].term);
fgets(words[i].des,50,glo);
printf("%s",words[i].term);
printf("%s",words[i].des);
}
fclose(glo);

printf("Please hit 1 to edit term only.\n");


printf("Please hit 2 to edit description only.\n");
printf("Please hit 3 to edit both term and description.\n");
scanf("%d",&choose);

if(choose==1)
{
printf("Please key in the term which is to be edited.");
scanf("%s",&mod);

for(i=0;i<100;i++)
{
if((strcmp(mod,words[i].term))==0)
{
printf("Please key in a new term to replace the old
term.");
scanf("%s",&words[i].term);
break;
}
}
}
else if(choose==2)
{
printf("Please key in the term which its description is to be
edited.");
scanf("%s",&mod);

for(i=0;i<100;i++)
{
if((strcmp(mod,words[i].term))==0)
{
fflush(stdin);
printf("Please key in a new description to
replace the old description.");
gets(words[i].des);
strncat(words[i].des,"\n",5);
strncat(words[i].term,"\t",5);
break;

35
}
}
}

else if (choose==3)
{
printf("Please key in the term which is to be edited.");
scanf("%s",&mod);

for(i=0;i<100;i++)
{
if((strcmp(mod,words[i].term))==0)
{
printf("Please key in a new term to replace the old
term.");
scanf("%s",&words[i].term);
fflush(stdin);
printf("Please key in a new description to replace
the old description.");
gets(words[i].des);
strncat(words[i].des,"\n",5);
strncat(words[i].term,"\t",5);
break;
}
}
}

printf("%s",words[i].term);
printf("%s",words[i].des);
fflush(stdin);

glo=fopen("test.txt","w");

for( i=0;i<100;i++)
{
fputs(words[i].term,glo);
fputs(words[i].des,glo);
}
fclose(glo);

void display(void)
{

glo=fopen("test.txt","r");
for(int i=0;i<100;i++)
{
fscanf(glo,"%s",words[i].term);

36
fgets(words[i].des,50,glo);
printf("%s",words[i].term);
printf("%s",words[i].des);
}
fclose(glo);

Problem Statement 5: Coding

#include <stdio.h>
#include <string.h>
#include <time.h>
#include<stdlib.h>

double mark(void);

void main()
{
char matrixno[100];
char name[100];
char idno[100];
double totalmark;
FILE *fp;
fp=fopen("Mark.txt","a+");

/*welcome note*/

printf("\n**********************************************************\
n");
printf("\n\t\t\tWELCOME\n");
printf("\n\t\tYou need to answer 5 question\n\t\tper set of question.\n");

printf("\n**********************************************************\
n");

/*get student no*/

printf("\n**********************************************************\
n");
fflush(stdin);
printf("\n\t\tName : ");
gets(name);
fflush(stdin);

printf("\n\t\tId Number :");


gets(idno);
fflush(stdin);

37
printf("\n\t\tMatrix Number :");
scanf("%s",&matrixno);
fflush(stdin);

printf("\n**********************************************************
*\n");
printf("\n\t\tLets the quiz begin!!\n\n");

totalmark=mark();

/*display student info and mark*/


printf("\n\t\tName : %s\n",name);
printf("\n\t\tMatrix Number : %s\n",matrixno);
printf("\n\t\tId Number : %s\n",idno);
printf("\n\t\tYour Mark : %.lf/100\n",totalmark);
printf("\n\t\tThanks for answering the quiz\n\n");

printf("\n**********************************************************
*\n");

/*write on a file*/
fprintf(fp,"\n\t\t\tStudent Mark\n\n");
fprintf(fp,"\n\tName :\t\t\t%s\n",name);
fprintf(fp,"\n\tMatrix Number :\t\t%s\n",matrixno);
fprintf(fp,"\n\tId Number :\t\t%s\n",idno);
fprintf(fp,"\n\tTotal Mark :\t\t%.lf/100\n",totalmark);

fclose(fp);

double mark(void)
{
char quest[26][100]={"Unit for resistor is ohm. Yes or No?","Unit for
current is ampere. Yes or No?","Unit for voltage is ohm. Yes or No?","Unit for
capacitor is farad. Yes or No?","Unit for inductor is ampere. Yes or No?","Total
impedence is z. Yes or No?","Resistor give resistance. Yes or No?","Unit for
power is watt. Yes or No?","Power is v x i. Yes or No?","V is circuit proportional
with current. Yes or No?","V is IR. Yes or No?","Conductance is 1/R. Yes or
No?","Power lost as heat. Yes or No?","Current is rate of charge flow. Yes or
No?","I is V/R. Yes or No?","Conductor act as insulator. Yes or No?","Heat
increase the resistivity. Yes or No?","Water is good conductor. Yes or No?","It is
better using parallel circuit. Yes or No?","RLC have no function in radio circuit.
Yes or No?","Transfomer increase and decrease voltage. Yes or No?","Earth wire
act to avoid short circuit. Yes or No?","Generator have induce voltage. Yes or
No?","Wire have tree type. Yes or No?", "The sinusoidal waveform begin from the
peak of value. Yes or No?"};

38
char
ans[26][100]={"yes","yes","no","yes","no","yes","yes","yes","yes","yes","yes","n
o","yes"," yes", "yes", "yes", "yes", "no",
"yes","no","yes","yes","yes","yes","no"};
char choice[20];
char check[10]={"begin"};
char answ[20];
char end[5]= {"end"};
int total_yes=0,total_no=0;
double right=0;
double wrong=0;
double x;
int y=5,q,r;
int *ptr=&y;

do
{

fflush(stdin);

for (r=0;r<*ptr;r++)
{
printf("\n\t\tQUESTION %d",r+1);
srand(time(0));
q=rand()%25;

printf("\n\t\t%s",quest[q]);
printf("\n\n\t\tAnswer:");
scanf("%s",answ);

fflush(stdin);

if(strcmp(answ,ans[q])==0)
{
right=right+1;

}
else
{
wrong=wrong+1;
}

/*diplay the answer*/


printf("\t\tThe answer is: %s\n\n", ans[q]);

}
/*calculate student mark*/
x=(right/(right+wrong))*100;

39
/*user choice*/

printf("\n**********************************************************
*\n");
printf("\n\n\nEnter 'begin' to continue and 'end' to end program:");
scanf("%s",choice);

printf("\n\n*********************************************************
**\n");

if (strcmp(choice,check)==0)

{
continue;
}
else
{
break;
}

}while(strcmp(end,choice)!=0);

return x;

40
Final Coding:

#include<stdio.h> //preprocessing directive


#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
#define pi 3.14159

void pbs1(void); //function prototype


void pbs2(void);
void pbs3(void);
void pbs4(void);
void pbs5(void);
void r_p(double k1);
void r_l(double k2);
void r_a(double k3);
void calculation(void);
void exit_prog(void);
double mark(void);
FILE*glo;
int address;
int counter=1;
char selection;
int *num=&address;
char mod[20];
char choose;

struct program

41
{
char term[50];
char des[150];
}words[100];

void add(void);
void edit(void);
void display(void);

void Ask4Exit(void);

char choice='y'; //value for restart

//mainline control
void main()
{
int choice0; //variable declaration
/*Sets the window title for the command prompt window.*/
system("title ********************** PBL C Program
**********************");

/*Sets the default console foreground and background colors.*/


system("color 71");

//decoration
printf("\nxx xx xx xxxxxx xx xxxxx xxxxx xx xx xxxxxx");
printf("\nxx xxxx xx xx xx xxxxxxx xxx xxx xxx xxx xx ");
printf("\n xxxxxxxx xxxx xx xx xx xx xxxx xxxx xxxx ");
printf("\n xxx xxx xx xxxxx xxxxxxx xxx xxx xx xxx xx xx ");
printf("\n xx xx xxxxxx xxxxx xxxxx xxxxx xx x xx xxxxxx");

printf("\n====================================================
======\n\n");

/*Suspends processing of a batch program and displays the message*/


system("pause");

//display the main page


while(choice=='y'||choice=='Y')
{
system("cls"); //Clears the
screen.

printf("\n\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\
4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4");
printf("\n\t\tPlease enter your choice");

42
printf("\n\t\t1. Problem Statement 1\n\t\t2. Problem Statement
2\n\t\t3. Problem Statement 3\n\t\t4. Problem Statement 4\n\t\t5.
Problem Statement 5");

printf("\n\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\
4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\n\n");
printf("Please enter your choice:");
scanf("%d",&choice0);

switch(choice0) //select
the question
{
case 1:pbs1();break;
case 2:pbs2();break;
case 3:pbs3();break;
case 4:pbs4();break;
case 5:pbs5();break;
default: printf("\n\aError input\nPlease enter again....");
}

printf("\n== @ == @ == HAVE A NICE DAY !! == @ == @ ==\n");


//end of program

void pbs1()
{
int total_num,counter =1;
double capacitance_series,capacitance_parallel;
double x;

int jawapan;

capacitance_parallel=0.0;
capacitance_series;

printf("############################################################
###################\n\n");
printf("\n\t\t\t ~///~\n\t\tWelcome to our program \n");
printf("\n\t\tThe simple program with 2 steps\n");
printf("\nThis program were provide to calculate the equivalent
capacitance\n");
printf("\nStep 1 : enter how many capacitor that you have in circuit\n");
printf("\nStep 2 : enter the value for each capacitor\n");
printf("\nStep 3 : done!\n\n");

43
printf("\nATTENTION PLEASE !!! --> PUT THE POSITIVE VALUE
ONLY\n\n");

printf("############################################################
###################\n\n");

do
{

do
{

printf("\nEnter total capacitor that you have in circuit :");


scanf("%d",&total_num);
if(total_num<=0)
printf("\n\t\tREINSERT DATA.\n\tYOUR DATA SHOULD BE
GREATER THAN ZERO\n\n");
}
while(total_num<=0);

while(total_num>0)
{

do
{
printf("\n\t->Enter value for each capacitor = ");
scanf("%lf",&x);
if(x<=0)
printf("\n\t\tREINSERT DATA.\n\tYOUR DATA SHOULD
BE GREATER THAN ZERO\n\n");
}
while(x<=0);

capacitance_series=1/(1/capacitance_series+1/x);
capacitance_parallel=capacitance_parallel+x;
total_num--;

}
printf("\n->Capacitance in series :->\t%.2f\n",capacitance_series);
printf("->Capacitance in parallel:->\t%.2f\n\n",capacitance_parallel);

44
printf("Do you want to continue?\n\nIf yes press 1.If no press 2 = ");
scanf("%d",&jawapan);

}
while(jawapan == 1);

Ask4Exit(); //exit the program


}

void pbs2()
{
double a,l,p,k1,k2,k3;
int counter=1;
int h;

printf("Enter cross-sectional area(A) value:");


scanf("%lf",&a);
printf("Enter length(l) value:");
scanf("%lf",&l);
printf("Enter resistivity(p) value:");
scanf("%lf",&p);
k1=l/a;
k2=p/a;
k3=p*l;

while (counter>=1)
{
printf("\nEnter \n(1)for relation R and p,\n(2)for relation R and
l,\n(3)for relation R and A:");
scanf("%d",&h);
switch(h)
{
case 1:
r_p(k1);
break;
case 2:
r_l(k2);
break;
case 3:
r_a(k3);
break;
}
}
}

void r_p(double k1)


{
double r1,r2,r3,p1,p2,p3;

45
char Answer;
int counter=1;

printf("\nThe k value is %.2f\n",k1);


do
{
printf("Enter resistivity(p1):");
scanf("%lf",&p1);
r1=p1*k1;
printf("Enter resistivity(p2):");
scanf("%lf",&p2);
r2=p2*k1;
printf("Enter resistivity(p3):");
scanf("%lf",&p3);
r3=p3*k1;

printf("\nWhen the resistivity is %.2f, the resistance is


%.2f.",p1,r1);
printf("\nWhen the resistivity is %.2f, the resistance is
%.2f.",p2,r2);
printf("\nWhen the resistivity is %.2f, the resistance is
%.2f.",p3,r3);

if(r1>r2&&r2>r3&&p1>p2&&p2>p3||
r1>r3&&r3>r2&&p1>p3&&p3>p2||r2>r1&&r1>r3&&p2>p1&&p1>p3||
r2>r3&&r3>r2&&p2>p3&&p3>p2||r3>r1&&r1>r2&&p3>p1&&p1>p2||
r3>r2&&r2>r1&&p3>p2&&p2>p1)
{
printf("\n\nWhen resistivity(p) increases, resistance(R) will
increases.\n");
printf("Therefore, resistivity(p) is proportional to
risistance(R).\n");
}
else
{
printf("\n\nError! There are two or three resistivity entered
are same value!\n");
printf("Please reinsert resistivity(p) with different
values.\n\n");
}

}while((r1==r2)||(r2==r3)||(r3==r1));
printf("\nDo you wish to continue verify the relation?(Y or
N): ");
scanf("%s",&Answer);
if ((Answer=='Y')||(Answer=='y'))
counter=1;

46
else
exit(1);

void r_l(double k2)


{
double r1,r2,r3,l1,l2,l3;
int counter=1;
char Answer;
printf("\nThe k value is %.2f\n",k2);

do
{
printf("Enter length1(l1) value:",l1);
scanf("%lf",&l1);
r1=l1*k2;
printf("Enter length2(l2) value:",l2);
scanf("%lf",&l2);
r2=l2*k2;
printf("Enter length3(l3) value:",l3);
scanf("%lf",&l3);
r3=l3*k2;

printf("\nWhen the length is %.2f, the resistance is %.2f.",l1,r1);


printf("\nWhen the length is %.2f, the resistance is %.2f.",l2,r2);
printf("\nWhen the length is %.2f, the resistance is %.2f.",l3,r3);

if(r1>r2&&r2>r3&&l1>l2&&l2>l3||r1>r3&&r3>r2&&l1>l3&&l3>l2||
r2>r1&&r1>r3&&l2>l1&&l1>l3||r2>r3&&r3>r2&&l2>l3&&l3>l2||
r3>r1&&r1>r2&&l3>l1&&l1>l2||r3>r2&&r2>r1&&l3>l2&&l2>l1)
{
printf("\n\nWhen length(l) increases, resistance(R) will
increases.\n");
printf("Therefore, length(l) is proportional to resistance(R).\n");
}
else
{
printf("\n\nError! There are two or three length entered are same
value!\n");
printf("Please reinsert length(l) with different values.\n\n");
}

}
while((l1==l2)||(l2==l3)||(l3==l1));
printf("\nDo you wish to continue verify the relation?(Y or
N): ");
scanf("%s",&Answer);
if ((Answer=='Y')||(Answer=='y'))
counter=1;

47
else
exit(1);
}
void r_a(double k3)
{
double r1,r2,r3,a1,a2,a3;
int counter=1;
char Answer;
printf("\nThe k value is %.2f\n",k3);

do
{
printf("Enter area1(A1) value:",a1);
scanf("%lf",&a1);
r1=k3/a1;
printf("Enter area2(A2) value:",a2);
scanf("%lf",&a2);
r2=k3/a2;
printf("Enter area3(A3) value:",a3);
scanf("%lf",&a3);
r3=k3/a3;

printf("\nWhen the area is %.2f, the resistance is %.2f.",a1,r1);


printf("\nWhen the area is %.2f, the resistance is %.2f.",a2,r2);
printf("\nWhen the area is %.2f, the resistance is %.2f.",a3,r3);

if(r1>r2&&r2>r3&&a1<a2&&a2<a3||
r1>r3&&r3>r2&&a1<a3&&a3<a2||r2>r1&&r1>r3&&a2<a1&&a1<a3||
r2>r3&&r3>r2&&a2<a3&&a3<a2||r3>r1&&r1>r2&&a3<a1&&a1<a2||
r3>r2&&r2>r1&&a3<a2&&a2<a1)
{
printf("\n\nWhen area(A) increases, resistance(R) will
decreases.\n");
printf("Therefore, area(A) is inversely proportional to
resistance(R).\n");
}
else
{
printf("\n\nThere are two or three area(A) entered are same
value.\n");
printf("Please reinsert the area(A) with different
value.\n\n");
}
}
while((a1==a2)||(a2==a3)||(a3==a1));
printf("\nDo you wish to continue verify the relation?(Y or
N): ");
scanf("%s",&Answer);
if ((Answer=='Y')||(Answer=='y'))
counter=1;

48
else
exit(1);

Ask4Exit();
}

void pbs3()
{
int ans;
do
{

printf("\nThis program will calculate the value for\n(i) v(t)\n(ii)


i(t)\nfor time interval 0 to 10 seconds for a circuit.");
printf("\nGiven that a series circuit that have the value of Vs= 10cos4t, R=
5 ohm\nand c= 0.1F.\n");

calculation();

printf("\nTo end this Problem Statement press '1'or '2' to continue:");


scanf("%d",&ans);
if (ans==1)
exit_prog();
}while (ans!=1);

Ask4Exit();
}

void calculation (void)


{
double v,c;
int t;
t=0;

printf("\n\nThe value for v(t) and i(t) for time interval 0 to 10


seconds is:");
while(t<=10)
{
v = 10*cos((4*t)*(pi/180));
c = (10*cos((4*t)*(pi/180)))/(3.2*cos
((4*t+51.34)*(pi/180)));
printf("\nWhen t=%d\tv(t)=%.2lf\ti(t)=%.2lf\n",t,v,c);
t++;
}
}

void exit_prog(void)
{

49
void pbs4()
{

while (counter==1)
{
printf("\nPlease hit A to enter a new term.");
printf("\nPlease hit B to edit or update term.");
printf("\nPlease hit C to display the term.");
printf("\nPlease hit D to exit the program.\n");
scanf("%c",&selection);

switch(selection)
{
case 'A':
add();
break;

case 'B':
edit();
break;

case 'C':
display();
break;

case 'D':
printf("Program terminating,...");
exit(1);
break;

}
fflush(stdin);
}

void add(void)
{

printf("Please key in the number of terms to be entered.");


scanf("%d",num);
fflush(stdin);
for(int i=0;i<*num;i++)
{
printf("Please key in term#%i: ",i+1);
gets(words[i].term);
printf("Please key in the '%s' description: ",words[i].term);

50
gets(words[i].des);
fflush(stdin);
}

glo=fopen("test.txt","a");

for( i=0;i<*num;i++)
{
fputs(words[i].term,glo);
fputs("\t",glo);
fputs(words[i].des,glo);
fputs("\n",glo);
}
fclose(glo);

void edit(void)
{

glo=fopen("test.txt","r");
for(int i=0;i<100;i++)
{
fscanf(glo,"%s",words[i].term);
fgets(words[i].des,50,glo);
printf("%s",words[i].term);
printf("%s",words[i].des);
}
fclose(glo);

printf("Please hit 1 to edit term only.\n");


printf("Please hit 2 to edit description only.\n");
printf("Please hit 3 to edit both term and description.\n");
scanf("%d",&choose);

if(choose==1)
{
printf("Please key in the term which is to be edited.");
scanf("%s",&mod);

for(i=0;i<100;i++)
{
if((strcmp(mod,words[i].term))==0)
{
printf("Please key in a new term to replace the old
term.");
scanf("%s",&words[i].term);
break;
}

51
}
}
else if(choose==2)
{
printf("Please key in the term which its description is to be
edited.");
scanf("%s",&mod);

for(i=0;i<100;i++)
{
if((strcmp(mod,words[i].term))==0)
{
fflush(stdin);
printf("Please key in a new description to
replace the old description.");
gets(words[i].des);
strncat(words[i].des,"\n",5);
strncat(words[i].term,"\t",5);
break;
}
}
}

else if (choose==3)
{
printf("Please key in the term which is to be edited.");
scanf("%s",&mod);

for(i=0;i<100;i++)
{
if((strcmp(mod,words[i].term))==0)
{
printf("Please key in a new term to replace the old
term.");
scanf("%s",&words[i].term);
fflush(stdin);
printf("Please key in a new description to replace
the old description.");
gets(words[i].des);
strncat(words[i].des,"\n",5);
strncat(words[i].term,"\t",5);
break;
}
}
}

printf("%s",words[i].term);
printf("%s",words[i].des);
fflush(stdin);

52
glo=fopen("test.txt","w");

for( i=0;i<100;i++)
{
fputs(words[i].term,glo);
fputs(words[i].des,glo);
}
fclose(glo);

void display(void)
{

glo=fopen("test.txt","r");
for(int i=0;i<100;i++)
{
fscanf(glo,"%s",words[i].term);
fgets(words[i].des,50,glo);
printf("%s",words[i].term);
printf("%s",words[i].des);
}
fclose(glo);

Ask4Exit();

void pbs5()
{
char matrixno[100];
char name[100];
char idno[100];
double totalmark;
FILE *fp;
fp=fopen("Mark.txt","a+");

/*welcome note*/

printf("\n**********************************************************\
n");
printf("\n\t\t\tWELCOME\n");
printf("\n\t\tYou need to answer 5 question\n\t\tper set of question.\n");

printf("\n**********************************************************\
n");

53
/*get student no*/

printf("\n**********************************************************\
n");
printf("\n\t\tName : ");
gets(name);
fflush(stdin);

printf("\n\t\tId Number :");


gets(idno);
fflush(stdin);

printf("\n\t\tMatrix Number :");


scanf("%s",&matrixno);
fflush(stdin);

printf("\n**********************************************************
*\n");
printf("\n\t\tLets the quiz begin!!\n\n");

totalmark=mark();

/*display student info and mark*/


printf("\n\t\tName : %s\n",name);
printf("\n\t\tMatrix Number : %s\n",matrixno);
printf("\n\t\tId Number : %s\n",idno);
printf("\n\t\tYour Mark : %.lf/100\n",totalmark);
printf("\n\t\tThanks for answering the quiz\n\n");

printf("\n**********************************************************
*\n");

/*write on a file*/
fprintf(fp,"\n\t\t\tStudent Mark\n\n");
fprintf(fp,"\n\tName :\t\t\t%s\n",name);
fprintf(fp,"\n\tMatrix Number :\t\t%s\n",matrixno);
fprintf(fp,"\n\tId Number :\t\t%s\n",idno);
fprintf(fp,"\n\tTotal Mark :\t\t%.lf/100\n",totalmark);

fclose(fp);

double mark(void)
{
char quest[26][100]={"Unit for resistor is ohm. Yes or No?","Unit for
current is ampere. Yes or No?","Unit for voltage is ohm. Yes or No?",

54
"Unit for capacitor is farad. Yes or
No?","Unit for inductor is ampere. Yes or No?","Total impedence is z. Yes or
No?",
"Resistor give resistance. Yes or
No?","Unit for power is watt. Yes or No?","Power is v x i. Yes or No?",
"V is circuit proportional with
current. Yes or No?","V is IR. Yes or No?","Conductance is 1/R. Yes or
No?","Power lost as heat. Yes or No?",
"Current is rate of charge flow. Yes
or No?","I is V/R. Yes or No?","Conductor act as insulator. Yes or No?","Heat
increase the resistivity. Yes or No?",
"Water is good conductor. Yes or
No?","It is better using parallel circuit. Yes or No?","RLC have no function in
radio circuit. Yes or No?",
"Transfomer increase and decrease
voltage. Yes or No?","Earth wire act to avoid short circuit. Yes or No?",
"Generator have induce voltage. Yes
or No?","Wire have tree type. Yes or No?", "The sinusoidal waveform begin from
the peak of value. Yes or No?"};
char
ans[26][100]={"yes","yes","no","yes","no","yes","yes","yes","yes","yes","yes",
"no","yes"," yes", "yes", "yes", "yes",
"no", "yes","no","yes","yes","yes","yes","no"};
char choice[20];
char check[10]={"begin"};
char answ[20];
char end[5]= {"end"};
int total_yes=0,total_no=0;
double right=0;
double wrong=0;
double x;
int y=5,q,r;
int *ptr=&y;

do
{

fflush(stdin);

for (r=0;r<*ptr;r++)
{
printf("\n\t\tQUESTION %d",r+1);
srand(time(0));
q=rand()%25;

printf("\n\t\t%s",quest[q]);
printf("\n\n\t\tAnswer:");
scanf("%s",answ);

55
fflush(stdin);

if(strcmp(answ,ans[q])==0)
{
right=right+1;

}
else
{
wrong=wrong+1;
}

/*diplay the answer*/


printf("\t\tThe answer is: %s\n\n", ans[q]);

}
/*calculate student mark*/
x=(right/(right+wrong))*100;

/*user choice*/

printf("\n**********************************************************
*\n");
printf("\n\n\nEnter 'begin' to continue and 'end' to end program:");
scanf("%s",choice);

printf("\n\n*********************************************************
**\n");

if (strcmp(choice,check)==0)

{
continue;
}
else
{
break;
}

}while(strcmp(end,choice)!=0);

return x;

Ask4Exit();
}

56
void Ask4Exit()
{
choice='t';

while(choice!='y'&&choice!='Y'&&choice!='n'&&choice!='N')
{
fflush(stdin);
printf("\nDo you want to return to main menu? Press y for yes or n
for no:");
scanf("%c",&choice);

if(choice!='y'&&choice!='Y'&&choice!='n'&&choice!='N')
printf("\a\nError input. Please enter again.");
}

7. Output & Testing


Problem Statement 1: Output

#####################################################################
##########
~///~
Welcome to our program
The simple program with 2 steps

57
This program were provide to calculate the equivalent capacitance
Step 1 : enter how many capacitor that you have in circuit
Step 2 : enter the value for each capacitor
Step 3 : done!
ATTENTION PLEASE !!! --> PUT THE POSITIVE VALUE ONLY
#####################################################################
##########
Enter total capacitor that you have in circuit :0

REINSERT DATA.
YOUR DATA SHOULD BE GREATER THAN ZERO

Enter total capacitor that you have in circuit :-1

REINSERT DATA.
YOUR DATA SHOULD BE GREATER THAN ZERO

Enter total capacitor that you have in circuit :3


->Enter value for each capacitor = 1
->Enter value for each capacitor = 2
->Enter value for each capacitor = 3
->Capacitance in series :-> 0.55
->Capacitance in parallel:-> 6.00

Do you want to continue?

If yes press 1.If no press 2 = 1

Enter total capacitor that you have in circuit :4


->Enter value for each capacitor = 0

REINSERT DATA.
YOUR DATA SHOULD BE GREATER THAN ZERO

->Enter value for each capacitor = -1

REINSERT DATA.
YOUR DATA SHOULD BE GREATER THAN ZERO

->Enter value for each capacitor = 1


->Enter value for each capacitor = 2
->Enter value for each capacitor = 3
->Enter value for each capacitor = 4

->Capacitance in series :-> 0.26


->Capacitance in parallel:-> 16.00

Do you want to continue?

58
If yes press 1.If no press 2 = 1

Enter total capacitor that you have in circuit :5

->Enter value for each capacitor = 1.04


->Enter value for each capacitor = 2.43
->Enter value for each capacitor = 1.24
->Enter value for each capacitor = 1.23
->Enter value for each capacitor = 1
->Capacitance in series :-> 0.13
->Capacitance in parallel:-> 22.94

Do you want to continue?

If yes press 1.If no press 2 = 2


Press any key to continue

Problem Statement 2: Output

Enter cross-sectional area(A) value:10


Enter length(l) value:15
Enter resistivity(p) value:12

Enter
(1)for relation R and p,
(2)for relation R and l,
(3)for relation R and A:1

59
The k value is 1.50
Enter resistivity(p1):1
Enter resistivity(p2):2
Enter resistivity(p3):3

When the resistivity is 1.00, the resistance is 1.50.


When the resistivity is 2.00, the resistance is 3.00.
When the resistivity is 3.00, the resistance is 4.50.

When resistivity(p) increases, resistance(R) will increases.


Therefore, resistivity(p) is proportional to risistance(R).

Do you wish to continue verify the relation?(Y or N): y

Enter
(1)for relation R and p,
(2)for relation R and l,
(3)for relation R and A:2

The k value is 1.20


Enter length1(l1) value:12
Enter length2(l2) value:13
Enter length3(l3) value:14

When the length is 12.00, the resistance is 14.40.


When the length is 13.00, the resistance is 15.60.
When the length is 14.00, the resistance is 16.80.

When length(l) increases, resistance(R) will increases.


Therefore, length(l) is proportional to resistance(R).

Do you wish to continue verify the relation?(Y or N): y

Enter
(1)for relation R and p,
(2)for relation R and l,
(3)for relation R and A:3

The k value is 180.00


Enter area1(A1) value:1
Enter area2(A2) value:2
Enter area3(A3) value:3

When the area is 1.00, the resistance is 180.00.


When the area is 2.00, the resistance is 90.00.
When the area is 3.00, the resistance is 60.00.

When area(A) increases, resistance(R) will decreases.


Therefore, area(A) is inversely proportional to resistance(R).

60
Do you wish to continue verify the relation?(Y or N):n
Press any key to continue

Problem Statement 3: Output

This program will calculate the value for


(i) v(t)
(ii) i(t)
for time interval 0 to 10 seconds for a circuit.
Given that a series circuit that have the value of Vs= 10cos4t, R= 5 ohm
and c= 0.1F.

61
The value for v(t) and i(t) for time interval 0 to 10 seconds is:
When t=0 v(t)=10.00 i(t)=5.00

When t=1 v(t)=9.98 i(t)=5.48

When t=2 v(t)=9.90 i(t)=6.07

When t=3 v(t)=9.78 i(t)=6.81

When t=4 v(t)=9.61 i(t)=7.80

When t=5 v(t)=9.40 i(t)=9.18

When t=6 v(t)=9.14 i(t)=11.28

When t=7 v(t)=8.83 i(t)=14.92

When t=8 v(t)=8.48 i(t)=22.85

When t=9 v(t)=8.09 i(t)=54.47

When t=10 v(t)=7.66 i(t)=-102.37

To exit press '1':

Problem Statement 4: Output

Please hit A to enter a new term.


Please hit B to edit or update term.
Please hit C to display the term.
Please hit D to exit the program.
A
Please key in the number of terms to be entered.3

62
Please key in term#1: aaa
Please key in the 'aaa' description: fff
Please key in term#2: bbb
Please key in the 'bbb' description: eee
Please key in term#3: ccc
Please key in the 'ccc' description: ddd

Please hit A to enter a new term.


Please hit B to edit or update term.
Please hit C to display the term.
Please hit D to exit the program.
B
aaa fff
bbb eee
ccc ddd
Please hit 1 to edit term only.
Please hit 2 to edit description only.
Please hit 3 to edit both term and description.
1
Please key in the term which is to be edited.bbb
Please key in a new term to replace the old term.ggg
ggg eee

Please hit A to enter a new term.


Please hit B to edit or update term.
Please hit C to display the term.
Please hit D to exit the program.
C
aaa fff
ggg eee
ccc ddd

Please hit A to enter a new term.


Please hit B to edit or update term.
Please hit C to display the term.
Please hit D to exit the program.
D
Program terminating,...Press any key to continue
Problem Statement 5: Output

63
64
65
Save file

66
Final Coding: Example Output for Problem Statement 1

67
8. Advantages
The program developed by our company consist a lot of advantages. Our
company decided combine all the five questions into one. The main menu will let user
to choose the question they want. This method is more user-friendly and easier to use.
Each of the questions has their own advantages. The following is the list of each
question advantages:

QUESTION 1:
• The program states clearly the type of arrangement that the user needs to choose,
so the user will not confuse.
• When the user inserts other arrangement of capacitance, the program will prompt
the user to reinsert the type of arrangement. User does not need to reopen that
program from the main menu.
• As we all know that the value of capacitance does not have negative value. So the
program only allow user to insert positive value as the capacitance value. If user
inserts negative value, the program will prompt the user to reinsert the value of
capacitance.
• After completing a calculation, the program will ask the user whether the user
wants to continue calculate other equivalent capacitance or wants to end the
program. This will enable the user to calculate another calculation without going
to main menu to choose this program again.

QUESTION 2:
• The program states clearly the relation that the user can choose.
• When the user choose ‘A’ which is the relation between the resistance and cross-sectional
area, the program will not allow the user to insert 3 cross-sectional area with the same
value. This is because same value cannot show the differences between resistance and
cross-sectional area. User can see the relation clearly when there are differences between
the resistance and cross-sectional area when the program displays the values.

QUESTION 3

68
• The program will calculate the v(t) and i(t) automatically with the values given in the
question 3.
• This program will show every v(t) and i(t) from time interval between 0 to 10 seconds.
So that the user can see how the values go when the time increases.

QUESTION 4
• The user can choose whether they want to add a new term, edit a term or
description and display all the terms that have been keyed it.
• The user can either update the term or description which is stored in the database
by replacing the term or description. This is very convenient for them and
systematic.

QUESTION 5
• Questions are randomised to let the user to answer different types of questions at
one time.
• The user can choose to continue to answer the questions or to end the questions
and view their results at anytime.

69
9. Recommendations
As a recommendation, for some problem statements, some improvement can be
done in order to make the program to be more useful and efficient. For problem
statement 1, the program should be developed that it can calculate the value of the
capacitors which are connected in both series and parallel. Moreover, for problem
statement 2, it will be better if the program can show the difference between the
resistance with resistivity, cross-sectional area and length of a material. Furthermore,
for problem statement 3, program can be designed to calculate the i(t) and the v(t) for
the time interval of 0 to 10 second for different circuit and values. In addition, for
problem statement 4, the program should be able to delete or remove the glossary.
Besides, for problem statement 5, the program should be designed such a way that the
students can choose which category of questions they want to answer.

70
10.Conclusion
We have succeed in coming out with an impressive program to overcome the
problems which are brought forward to us in this POPBL assignment. We used
Microsoft Visual C++ to generate the source code. C programming allows us to learn
structured programming and proper programming techniques. C programming syntax
and coding style is simple, suitable for complex engineering applications and
portable, can be executed on different operating system. A pseudo code is a short
English phrases with a limited vocabulary that are used to describe the algorithm (the
processing steps). A pseudo code must have a limited vocabulary, easy to learn,
produce simple English-like narrative notation and capable of describing all
algorithms, regardless of their complexity. Flowcharting is a graphical technique for
algorithm design and representation is equivalent to pseudo coding and can be used as
an alternative.
Finally after months of endless work and good teamwork form by us, the group
members, this POPBL assignment was finally done. We owed our gratitude to the
more efficient group members for guiding the weaker group members during this
period and contributions from all the group members allow us to complete this
POPBL assignment on time. We have learned to identify and apply software
development method to solve problems based on domain problems constructively. We
were also able to create a computer systematically using C programming language.
We have mastered the skills to analyze and debug a computer program correctly. As
well as our group members were able to communicate effectively in written and
spoken during our POPBL assignment. We are proud of the knowledge gained in
producing documentation and orally presenting the output.

71
11.Bibliography
1. B.A. Forouzan and R.R. Gilberg (2001), Computer Science: A structured
Programming Approach using C, US: Brooks/Cole.
2. Collopy D.M. (2003), Introduction to C Programming: A Modular Approach,
New Jersey: Prentice Hall.
3. Gottfried B. (1996), Programming with C, Second Edition, Schaum’s Outline
Series: Mc Graw Hill.
4. Shamsul Mohamad. Khalid Isa, Zarina Tukiran, Noraisah Sudin, ‘A’ for C
Programming. Pernerbit UTHM.
5. http://www.cplusplus.com

72
12.Appendix
Problem Statement 1:

1. The user needs to insert the number of capacitors, n.


2. The user needs to insert the values of the capacitance, C. If the value is
negative, the program will display error statement and prompt the user to
reinsert the value of capacitors. This is because capacitor does not have
negative value.
3. Calculate the equivalent capacitance by using the following formula:
For Parallel: capacitance_parallel
For Series: 1/(1/capacitance_series+1/x)
4. Display the output of the program to show the equivalent capacitance for
parallel and series.
5. User determine whether want to continue this program or end.

Problem Statement 2:

1. User enter the value for:


A = Cross-sectional area, A
B = Resistivity, ρ
C = Length, l
2. Then the user need to choose:
1 = relation R and p
2 = relation R and l
3 = relation R and A
3. If the user chooses 1:
• User need to insert value of three value resistivity,. If user inserts 2 or 3
cross-sectional areas with the same the values, the program will prompt
user to reinsert value. This is because cross-sectional area with same value
cannot show the relation clearly.
• Calculate resistance by using formula R = (ρ*ℓ)/A

73
• Show the value of resistance and determine the condition.
• Show the relation.
3. If user choose relation 2:
• User need to insert three value of length. If user insert 2 or 3 length with
the same values, the program will prompt the user to reinsert the value of
resistivity.
• Calculate resistance by using formula R = (ρ*ℓ)/A
• Show the value of resistance and determine the condition.
• Show the relation.
4. If user choose relation 3:
• User need to insert three value of cross-sectional area. If user inserts 2 or
3 length with the same values, the program will prompt the user to reinsert
the value of length.
• Calculate resistance by using formula R = (ρ*ℓ)/A
• Show the value of resistance and determine the condition.
• Show the relation.
5. User determine whether want to continue this program or end it.

Problem Statement 3:

The program will display all the values of voltage v(t) and i(t) in degree form for
time interval of 0 to 10 second. The program will end when the user press ‘1’.

Problem Statement 4:

1. The user need input what is needed to do that is key ‘A’ for adding term, key ‘B’
for edit term, key ‘C’ for display term and key D to end.
2. User needs to input the numbers of term that is being keyed in.
3. Then the program will prompt the user to key in the terms and descriptions
4. Next, the program will prompt the user again on what is needed to do that is add
term, edit term, display term and end the program.

74
5. The process is repeated if the user wants to edit the terms or description. The
program will stop when the user choose option D to end, then only the program
will terminate.
Problem Statement 5:

1. The user need input name, ID number and matrix number.


2. The user’s name, ID number and matrix number will automatically record into
text file.
3. The program will randomly generate 5 questions.
4. Display the 5 questions at a time and user need to answer the questions one by
one.
5. For the answer is Yes, the user need to type ‘yes’. For the answer is No, the user
need to type ‘no’.
6. Program will calculate the total marks and total of correct and wrong answers.
7. Record the total marks into text file.
1. Determine whether there are other user wants to answer this yes or no quiz
program or want to end the program.

75