You are on page 1of 2

Programming Techniques Lab LAB Exam

CMP N103 1/2



Given the following code
Class CircElem:
CircElem.h
#pragma once
class CircElem //Circuit Element (Resistor, Inductor,....)
{
public:
//Calculate Impedance given Frequency
virtual double CalcImp(double Freq) = 0;
};

main function:
Main.cpp
#include "Resistor.h"
#include "Inductor.h"
#include <iostream>
using namespace std;

//Write your name as a comment in the next line
//Name:

void main()
{
/*Required [1]:
Create an array "Circuit" of 2 circuit elements pointers*/
;

/*Required [2]:
Dynamically create an object of class Resistor with value 100*/
Circuit[0] = ;

/*Required [3]:
Dynamically create an object of class Inductor with value 50*/
Circuit[1] = ;


for(int i=0; i<2; i++)
{
cout<<"\nImpedance value of element #"<<i+1<<" is:";
cout<<Circuit[i]->CalcImp(30);
}
cout<<endl;

/*Required[4]:
use pointer Circuit[0] to call function setRvalue(300)*/
;

for(int i=0; i<2; i++)
{
cout<<"\nImpedance value of element #"<<i+1<<" is:";
cout<<Circuit[i]->CalcImp(50);
}
}
CairoUniversity
Faculty of Engineering
Credit Hours System

CMP N103
ProgrammingTechniques Lab

Time: 60 min
LABExam- Sample 1

!"#$ :
%&$ :
PDF created with pdfFactory trial version www.pdffactory.com
Programming Techniques Lab LAB Exam
CMP N103 2/2

Requirements

1- Create two classes to represent the following types of circuit elements
a. Class Resistor that has a private member called Rvalue for resistance value
b. Class Inductor to represent inductor with a private member called Inductance

2- For each of the two classes created in part 1,

a- Add a non-default constructor to initialize its member
b- Override function double CalcImp(double Freq) to calculate impedance Z as follows:
i. Z

=! (where R is the resistance value)



ii. Z
"
=2#$% (where f is the frequency and L is the inductance)


3- For class Resistor, add a member function setValue(double R) to set Rvalue

4- Complete the main function as instructed by the comments

5- Compile and run the program to produce the following output.

Program Output
Impednace value of element #1 is:100
Impednace value of element #2 is:9420

Impednace value of element #1 is:300
Impednace value of element #2 is:15700


Notes:
- Do not change class CircElem
- Write your name at the beginning of Main.cpp file (on the computer)


[2 mark]
[6 marks]
[1 marks]
[4 marks]
[2 marks]
PDF created with pdfFactory trial version www.pdffactory.com

You might also like