Roll No. Total No. of Pages : 03
Total No. of Questions : 18
--- Content provided by FirstRanker.com ---
B.Tech. (Electrical & Electronics Engg. / Electronics & Electrical)
(2018 Batch) (Sem.=3)
ELECTRICAL CIRCUIT ANALYSIS
Subject Code : BTEEE-301-18
M.Code : 76463
--- Content provided by FirstRanker.com ---
Time : 3 Hrs. Max. Marks : 60INSTRUCTIONS TO CANDIDATES :
- SECTION-A is COMPULSORY consisting of TEN questions carrying TWO marks each.
- SECTION-B contains FIVE questions carrying FIVE marks each and students have to attempt any FOUR questions.
- SECTION-C contains THREE questions carrying TEN marks each and students have to attempt any TWO questions.
--- Content provided by FirstRanker.com ---
SECTION-A
Write briefly :
- State Reciprocity Theorem and its application.
- What is coefficient of coupling?
- Write various applications of filters?
- What are open circuit parameters? Give the equivalent circuit.
- State advantages of 3-phase machines over 1-phase machines.
- The coupled coil with L1 = 3H, L2 = 1mH and K = 0.5 are connected in series additive arrangement. Calculate the equivalent inductance.
- What do you mean by duality network?
- What is the difference between network synthesis and network analysis?
- Give the condition for selecting the resonant frequency in m-derived high pass and low-pass filters.
- What do you mean by immittance?
--- Content provided by FirstRanker.com ---
--- Content provided by FirstRanker.com ---
SECTION-B
- For the given two port network calculate the short circuit parameters of Fig. 1.
--- Content provided by FirstRanker.com ---
#include
#includeusing namespace std; // Structure to represent a process
struct Process { int id; int arrivalTime; int burstTime; int completionTime; int turnaroundTime; int waitingTime;
}; // Function to calculate completion time, turnaround time, and waiting time for each process
void calculateTimes(vector& processes) { int currentTime = 0; for (int i = 0; i < processes.size(); ++i) { currentTime += processes[i].burstTime; firstranker.completionTime = currentTime; processes[i].turnaroundTime = firstranker.completionTime - processes[i].arrivalTime; processes[i].waitingTime = processes[i].turnaroundTime - processes[i].burstTime; } --- Content provided by FirstRanker.com ---
} // Function to sort processes by arrival time
bool compareByArrivalTime(const Process& a, const Process& b) { return a.arrivalTime < b.arrivalTime;
} // Function to sort processes by burst time (for SJF)
bool compareByBurstTime(const Process& a, const Process& b) { return a.burstTime < b.burstTime;
} // Function to perform First-Come, First-Served (FCFS) scheduling--- Content provided by FirstRanker.com ---
void fcfs(vectorprocesses) { sort(processes.begin(), processes.end(), compareByArrivalTime); calculateTimes(processes); cout << "FCFS Scheduling:" << endl; cout << "Process\tArrival Time\tBurst Time\tCompletion Time\tTurnaround Time\tWaiting Time" << endl; for (const auto& process : processes) { cout << process.id << "\t\t" << process.arrivalTime << "\t\t" << process.burstTime << "\t\t" << firstranker.completionTime << "\t\t" << process.turnaroundTime << "\t\t" << process.waitingTime << endl; }
} // Function to perform Shortest Job First (SJF) scheduling
void sjf(vectorprocesses) { sort(processes.begin(), processes.end(), compareByArrivalTime); vector readyQueue; vector completedProcesses; int currentTime = 0; while (completedProcesses.size() < processes.size()) { // Add processes to the ready queue that have arrived for (int i = 0; i < processes.size(); ++i) { if (processes[i].arrivalTime <= currentTime && find_if(readyQueue.begin(), readyQueue.end(), [&](const Process& p){ return p.id == processes[i].id; }) == readyQueue.end() && find_if(completedProcesses.begin(), completedProcesses.end(), [&](const Process& p){ return p.id == processes[i].id; }) == completedProcesses.end()) { readyQueue.push_back(processes[i]); } } // If the ready queue is empty, increment the current time and continue if (readyQueue.empty()) { currentTime++; continue; } // Sort the ready queue by burst time sort(readyQueue.begin(), readyQueue.end(), compareByBurstTime); // Select the process with the shortest burst time Process shortestJob = readyQueue[0]; readyQueue.erase(readyQueue.begin()); // Update the current time and calculate completion time, turnaround time, and waiting time currentTime += shortestJob.burstTime; firstranker.completionTime = currentTime; shortestJob.turnaroundTime = firstranker.completionTime - shortestJob.arrivalTime; shortestJob.waitingTime = shortestJob.turnaroundTime - shortestJob.burstTime; // Add the completed process to the completed processes vector completedProcesses.push_back(shortestJob); } cout << "SJF Scheduling:" << endl; cout << "Process\tArrival Time\tBurst Time\tCompletion Time\tTurnaround Time\tWaiting Time" << endl; for (const auto& process : completedProcesses) { cout << process.id << "\t\t" << process.arrivalTime << "\t\t" << process.burstTime << "\t\t" << firstranker.completionTime << "\t\t" << process.turnaroundTime << "\t\t" << process.waitingTime << endl; }
} int main() { int n; cout << "Enter the number of processes: "; cin >> n; vectorprocesses(n); for (int i = 0; i < n; ++i) { processes[i].id = i + 1; cout << "Enter arrival time for process " << i + 1 << ": "; cin >> processes[i].arrivalTime; cout << "Enter burst time for process " << i + 1 << ": "; cin >> processes[i].burstTime; } fcfs(processes); cout << endl; sjf(processes); return 0;
} **Explanation:** 1. **Includes:** * ``: For input/output operations (like `cout` and `cin`). * ` `: For using dynamic arrays (vectors) to store processes. * ` `: For sorting algorithms (`sort`) and other useful functions. 2. **`Process` struct:** * Defines a structure to hold information about each process: * `id`: Process identifier. * `arrivalTime`: The time the process arrives in the ready queue. * `burstTime`: The time required to execute the process. * `completionTime`: The time the process finishes execution. * `turnaroundTime`: The time from arrival to completion (completionTime - arrivalTime). * `waitingTime`: The time the process spends waiting in the ready queue (turnaroundTime - burstTime). 3. **`calculateTimes(vector & processes)` function:** * Calculates the `completionTime`, `turnaroundTime`, and `waitingTime` for each process in the given vector. * It assumes the processes are already in the order they will be executed. * `currentTime` keeps track of the current time in the simulation. 4. **`compareByArrivalTime(const Process& a, const Process& b)` function:** * A comparison function used by `sort` to sort processes based on their arrival time. It returns `true` if `a` should come before `b` in the sorted order (i.e., `a` has an earlier arrival time). 5. **`compareByBurstTime(const Process& a, const Process& b)` function:** * A comparison function used by `sort` to sort processes based on their burst time. It returns `true` if `a` should come before `b` in the sorted order (i.e., `a` has a shorter burst time). 6. **`fcfs(vector processes)` function:** * Implements the First-Come, First-Served (FCFS) scheduling algorithm. * It first sorts the processes by arrival time using `sort` and `compareByArrivalTime`. * Then, it calls `calculateTimes` to calculate the completion, turnaround, and waiting times. * Finally, it prints the results in a table format. 7. **`sjf(vector processes)` function:** * Implements the Shortest Job First (SJF) scheduling algorithm. * It first sorts the processes by arrival time using `sort` and `compareByArrivalTime`. * It uses a `readyQueue` (a vector) to hold processes that have arrived and are ready to be executed. * It uses a `completedProcesses` vector to store the processes that have finished execution. * The `while` loop continues until all processes have been completed. * Inside the loop: * It adds processes to the `readyQueue` that have arrived by comparing `arrivalTime` with `currentTime`. * If the `readyQueue` is empty, it increments `currentTime` and continues to the next iteration. * It sorts the `readyQueue` by burst time using `sort` and `compareByBurstTime`. * It selects the process with the shortest burst time from the `readyQueue`. * It updates `currentTime` and calculates the completion, turnaround, and waiting times for the selected process. * It adds the completed process to the `completedProcesses` vector. * Finally, it prints the results in a table format. 8. **`main()` function:** * Prompts the user to enter the number of processes. * Creates a `vector ` to store the processes. * Prompts the user to enter the arrival time and burst time for each process. * Calls the `fcfs` and `sjf` functions to perform the scheduling algorithms. * Returns 0 to indicate successful execution. **How to Compile and Run:** 1. **Save:** Save the code as a `.cpp` file (e.g., `scheduling.cpp`). --- Content provided by FirstRanker.com ---
2. **Compile:** Open a terminal or command prompt and use a C++ compiler (like gThis download link is referred from the post: PTU B.Tech Question Papers 2020 December (All Branches)
--- Content provided by FirstRanker.com ---