Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Al-Mustansiriyah University Class: 2nd Class

College of Engineering Time: 3 Hours


Electrical Eng. Department Lecturers: Asst. Lect. Gregor A. Aremice
Subject: Computer Programming Asst. Lect. Jaafar Q. Kadhim
Final Exam
2013-2014
.‫ االجببة على خمسة اسئلة فقط مع ذكر السؤال المراد تركه في بداية الدفتر‬:‫مالحظة‬
C-Language
Q1: For any half-adder block, the operation is shown in figure (1):

Input 1 Input 1 Input 2


Input 2 H.A Input 1 Input 2

Figure (1)
Write a C-language program to implement the logic circuit shown in figure (2) for any inputs,
your program should repeat executing until you press (0) and at least it should run for one time
if you press (0) at first time execution.
A S1
B H.A C1
S2
Ci H.A C2

Figure (2) (02 marks)

Q2: Write a C-language program to read (n) integer numbers, and then find the maximum
number and its location. (02 marks)

Q3: Using pointers, write a C-Language program to convert a circuit containing resistors
connected in delta ( ) configuration to star ( ) configuration.

RA
R1 R2

(25 marks)

RB RC R3

Recall:

(02 marks)

ً‫اقلب الصفحة رجبءا‬


MATLAB

Q4: In a communication system, suppose a message signal ( ) and its carrier signal ( ) are
given respectively as follows:
( ) ( ) ( )
( ) ( )
and a double-sideband suppressed carrier ( ) is given as
( ) ( ) ( )
Write a MATLAB program to plot ( ), ( ) and ( ) using the subplot command, for
( ) in steps of ( ).
(20 marks)

Q5: If the synchronous speed ( ) of an Induction Motor (IM) is given by:

and, the rotor speed ( ) of an Induction Motor (IM) is given by:

( )

Then, for any values of frequency ( ), number of poles as a vector ( ), and slip ( ), built a
MATLAB user defined function named (motor) that plots the above relations on the same plot
area as follows; plot ( vs. ) with (red) colored (dotted) curve with (diamond) markers, and
plot ( vs. ) with (blue) colored (dotted) curve with (square) markers.
(20 marks)

Q6: Write a MATLAB program to find I1, I2 and I3 from the circuit shown below using mesh
method:

(20 marks)

Good Luck
First Prototype Solutions
‫االجوبت النموذجيت ألسئلت النموذج االول لمبدة الحبسببث‬
)‫ (الدور االول‬3102-3102

(Note: Answer Five Questions)


C-Language
Q1:
#include<stdio.h>
main()
{
int A,B,Ci,S1,C1,S2,C2,choice;

do
{
printf("enter choice of execution: ");
scanf("%d",&choice);
printf("\nEnter input A: ");
scanf("%d",&A);
printf("Enter input B: ");
scanf("%d",&B);
printf("Enter input Ci: ");
scanf("%d",&Ci);
S1=A^B;
C1=A&B;
S2=C1^Ci;
C2=C1&Ci;
printf("S1=%d \n S2=%d \n C2=%d\n",S1,S2,C2);

}while(choice!=0);
}

Q2:
#include<stdio.h>
#include<conio.h>
main()
{
int a[100],max,i,z;
printf("enter element for the array: ");
for(i=0;i<100;i++)
scanf("%d",&a[i]);
max=a[0];
z=0;
for(i=1;i<100;i++)
{
if(max<a[i])
{max=a[i];
z=i;}}
printf("maximum no= %d location %d",max, z);
getch();
}
First Prototype Solutions
‫االجوبت النموذجيت ألسئلت النموذج االول لمبدة الحبسببث‬
)‫ (الدور االول‬3102-3102

Q3:
#include<stdio.h>
main()
{
float R1,R2,R3,RA,RB,RC,*pR1,*pR2,*pR3,*pRA,*pRB,*pRC;
pR1=&R1;
pR2=&R2;
pR3=&R3;
pRA=&RA;
pRB=&RB;
pRC=&RC;
printf("Enter RA value: ");
scanf("%f",pRA);
printf("Enter RB value: ");
scanf("%f",pRB);
printf("Enter RC value: ");
scanf("%f",pRC);
*pR1=(*pRB*(*pRC))/(*pRA+*pRB+*pRC);
*pR2=(*pRA*(*pRC))/(*pRA+*pRB+*pRC);
*pR3=(*pRA*(*pRB))/(*pRA+*pRB+*pRC);
printf("R1=%f \t R2=%f \t R3=%f",*pR1,*pR2,*pR3);
}
MATLAB
Q4:
clc
clear all
t=pi:0.1*pi:2*pi;
m=4*cos(120*pi*t)+2*cos(300*pi*t);
c=4*cos(10000*pi*t);
s=m.*c;
subplot(3,1,1), plot(t,m)
subplot(3,1,2), plot(t,c)
subplot(3,1,3), plot(t,s)

Q5:
function [Ns Nr]=motor(f,P,S)
Ns=(f*120)./P;
Nr=(1-S)*Ns;
plot(P,Ns,'rd:',P,Nr,'bs:')

Q6:
clc
clear all
R=[10 -9 0; -9 20 -9; 0 -9 15];
V=[100 0 0]';
I=R\V;
disp('I1=');
disp(I(1))
disp('I2=');
disp(I(2))
disp('I3=');
disp(I(3))
M=inv(R)*V

You might also like