1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
igomit [66]
3 years ago
10

More discussion about seriesConnect(Ohm) function In your main(), first, construct the first circuit object, called ckt1, using

the class defined above. Use a loop to call setOneResistance() function to populate several resistors. Repeat the process for another circuit called ckt2. Develop a member function called seriesConnect() such that ckt2 can be connected to ckt1 using instruction ckt1.seriesConnect(ckt2).
Engineering
1 answer:
STALIN [3.7K]3 years ago
8 0

Answer:

resistor.h

//circuit class template

#ifndef TEST_H

#define TEST_H

#include<iostream>

#include<string>

#include<vector>

#include<cstdlib>

#include<ctime>

#include<cmath>

using namespace std;

//Node for a resistor

struct node {

  string name;

  double resistance;

  double voltage_across;

  double power_across;

};

//Create a class Ohms

class Ohms {

//Attributes of class

private:

  vector<node> resistors;

  double voltage;

  double current;

//Member functions

public:

  //Default constructor

  Ohms();

  //Parameterized constructor

  Ohms(double);

  //Mutator for volatage

  void setVoltage(double);

  //Set a resistance

  bool setOneResistance(string, double);

  //Accessor for voltage

  double getVoltage();

  //Accessor for current

  double getCurrent();

  //Accessor for a resistor

  vector<node> getNode();

  //Sum of resistance

  double sumResist();

  //Calculate current

  bool calcCurrent();

  //Calculate voltage across

  bool calcVoltageAcross();

  //Calculate power across

  bool calcPowerAcross();

  //Calculate total power

  double calcTotalPower();

  //Display total

  void displayTotal();

  //Series connect check

  bool seriesConnect(Ohms);

  //Series connect check

  bool seriesConnect(vector<Ohms>&);

  //Overload operator

  bool operator<(Ohms);

};

#endif // !TEST_H

resistor.cpp

//Implementation of resistor.h

#include "resistor.h"

//Default constructor,set voltage 0

Ohms::Ohms() {

  voltage = 0;

}

//Parameterized constructor, set voltage as passed voltage

Ohms::Ohms(double volt) {

  voltage = volt;

}

//Mutator for volatage,set voltage as passed voltage

void Ohms::setVoltage(double volt) {

  voltage = volt;

}

//Set a resistance

bool Ohms::setOneResistance(string name, double resistance) {

  if (resistance <= 0){

      return false;

  }

  node n;

  n.name = name;

  n.resistance = resistance;

  resistors.push_back(n);

  return true;

}

//Accessor for voltage

double Ohms::getVoltage() {

  return voltage;

}

//Accessor for current

double Ohms::getCurrent() {

  return current;

}

//Accessor for a resistor

vector<node> Ohms::getNode() {

  return resistors;

}

//Sum of resistance

double Ohms::sumResist() {

  double total = 0;

  for (int i = 0; i < resistors.size(); i++) {

      total += resistors[i].resistance;

  }

  return total;

}

//Calculate current

bool Ohms::calcCurrent() {

  if (voltage <= 0 || resistors.size() == 0) {

      return false;

  }

  current = voltage / sumResist();

  return true;

}

//Calculate voltage across

bool Ohms::calcVoltageAcross() {

  if (voltage <= 0 || resistors.size() == 0) {

      return false;

  }

  double voltAcross = 0;

  for (int i = 0; i < resistors.size(); i++) {

      voltAcross += resistors[i].voltage_across;

  }

  return true;

}

//Calculate power across

bool Ohms::calcPowerAcross() {

  if (voltage <= 0 || resistors.size() == 0) {

      return false;

  }

  double powerAcross = 0;

  for (int i = 0; i < resistors.size(); i++) {

      powerAcross += resistors[i].power_across;

  }

  return true;

}

//Calculate total power

double Ohms::calcTotalPower() {

  calcCurrent();

  return voltage * current;

}

//Display total

void Ohms::displayTotal() {

  for (int i = 0; i < resistors.size(); i++) {

      cout << "ResistorName: " << resistors[i].name << ", Resistance: " << resistors[i].resistance

          << ", Voltage_Across: " << resistors[i].voltage_across << ", Power_Across: " << resistors[i].power_across << endl;

  }

}

//Series connect check

bool Ohms::seriesConnect(Ohms ohms) {

  if (ohms.getNode().size() == 0) {

      return false;

  }

  vector<node> temp = ohms.getNode();

  for (int i = 0; i < temp.size(); i++) {

      this->resistors.push_back(temp[i]);

  }

  return true;

}

//Series connect check

bool Ohms::seriesConnect(vector<Ohms>&ohms) {

  if (ohms.size() == 0) {

      return false;

  }

  for (int i = 0; i < ohms.size(); i++) {

      this->seriesConnect(ohms[i]);

  }

  return true;

}

//Overload operator

bool Ohms::operator<(Ohms ohms) {

  if (ohms.getNode().size() == 0) {

      return false;

  }

  if (this->sumResist() < ohms.sumResist()) {

      return true;

  }

  return false;

}

main.cpp

#include "resistor.h"

int main()

{

   //Set circuit voltage

  Ohms ckt1(100);

  //Loop to set resistors in circuit

  int i = 0;

  string name;

  double resistance;

  while (i < 3) {

      cout << "Enter resistor name: ";

      cin >> name;

      cout << "Enter resistance of circuit: ";

      cin >> resistance;

      //Set one resistance

      ckt1.setOneResistance(name, resistance);

      cin.ignore();

      i++;

  }

  //calculate totalpower and power consumption

  cout << "Total power consumption = " << ckt1.calcTotalPower() << endl;

  return 0;

}

Output

Enter resistor name: R1

Enter resistance of circuit: 2.5

Enter resistor name: R2

Enter resistance of circuit: 1.6

Enter resistor name: R3

Enter resistance of circuit: 1.2

Total power consumption = 1886.79

Explanation:

Note

Please add all member function details.Its difficult to figure out what each function meant to be.

You might be interested in
A circular ceramic plate that can be modeled as a blackbody is being heated by an electrical heater. The plate is 30 cm in diame
MakcuM [25]

Answer:

Heater power = 425 watts

Explanation:

Detailed explanation and calculation is shown in the image below

6 0
2 years ago
If you are a government authority what extend will you modify the existing policy
mr_godi [17]

Answer:

kk

Explanation:

dkdndidodd ndidkjeeiwonejeeidmdnddkdidfmndd

4 0
3 years ago
What is the primary water source for a water cooled recovery unit's condensing coll?
nataly862011 [7]
A) chilled water from evaporator
7 0
3 years ago
Drivers education - Unit 3
melamori03 [73]

The following scenarios are pertinent to driving conditions that one may encounter. See the following rules of driving.

<h3>What do you do when the car is forced into the guardrail?</h3>

Best response:

  • I'll keep my hands on the wheel and slow down gradually.
  • The reason I keep my hands on the steering wheel is to avoid losing control.
  • This will allow me to slowly back away from the guard rail.
  • The next phase is to gradually return to the fast lane.
  • Slamming on the brakes at this moment would result in a collision with the car behind.

Scenario 2: When driving on a wet road and the car begins to slide

Best response:

  • It is not advised to accelerate.
  • Pumping the brakes is not recommended.
  • Even lightly depressing and holding down the brake pedal is not recommended.
  • The best thing to do is take one foot off the gas pedal.
  • There should be no severe twists at this time.

Scenario 3: When you are in slow traffic and you hear the siren of an ambulance behind

Best response:

  • The best thing to do at this moment is to go to the right side of the lane and come to a complete stop.
  • This helps to keep the patient in the ambulance alive.
  • It also provide a clear path for the ambulance.
  • Moving to the left is NOT recommended.
  • This will exacerbate the situation. If there is no place to park on the right shoulder of the road, it is preferable to stay in the lane.

Learn more about rules of driving. at;

brainly.com/question/8384066

#SPJ1

4 0
1 year ago
When passing another vehicle, when is it acceptable to drive over the
miss Akunina [59]

Answer:

Under no circumstances

Explanation:

I'm not 100% sure why, but I remember hearing that you're not suposed to go over the speed limit no matter what

7 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is not an example of heat generation? a)- Exothermic chemical reaction in a solid b)- Endothermic Chemica
    15·1 answer
  • The water behind Hoover Dam is 206m higher than the Colorado river below it. At what rate must water pass through the hydraulic
    15·2 answers
  • A 10-mm steel drill rod was heat-treated and ground. The measured hardness was found to be 290 Brinell. Estimate the endurance s
    14·1 answer
  • 1. The area of the given triangle is 25 square units. What is the value of x?<br> X+2
    8·1 answer
  • Can a real refrigerator have higher COP than the COP of the Carnot refrigerator?
    7·2 answers
  • what is the expected life 1 inch diameter bar machined from AISI 1020 CD Steel is subjected to alternating bending stress betwee
    9·1 answer
  • Which of the following can cause a flopping sound at the front of the engine
    14·1 answer
  • Three-dimensional measuring references all of these EXCEPT:
    10·1 answer
  • An open top concrete tank is available to a construction crew to store water. The job site has a daily requirement for 500 gallo
    10·1 answer
  • When hermetic refrigerant motor-compressors are designed to operate continuously at currents greater than 156 percent of the rat
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!