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
Which type of finish is absorbed into the wood?
stiks02 [169]
Penetrating finishes are absorbed by the wood and dry inside the wood. Interior wood stain is used to accentuate the grain in natural woods or plywood while still adding some color. While wood stains offer some level of protection on wood, it's recommended to use stain in combination with a surface finish.
7 0
3 years ago
Which statements describe how the Fed responds to high inflation? Check all that apply.
Sveta_85 [38]
Answer:
• it charges banks more interest
• it sells more securities
• it decreases the money supply

In response to high inflation, the Fed charges banks more interests and pays the banks less interests. It also sells not securities.
8 0
2 years ago
Rosalind franklin<br> What was she famous for
liq [111]

Answer:

She was known for her work on X-ray diffraction images of DNA, which led to the discovery of the DNA double helix for which Francis Crick, James Watson, and Maurice Wilkins shared the Nobel Prize in Physiology or Medicine in 1962.

Explanation:

5 0
3 years ago
For installations where the nonlinear load is huge, most consulting engineers will specify ____-rated transformers.
Scorpion4ik [409]

Answer:

K

Explanation:

For installations where the nonlinear load is huge, most consulting engineers will specify K-rated transformers.

8 0
2 years ago
(Signal Property) Under what condition is a discrete-time signal x[????] or a continuous-time signal x(????) periodic? Determine
Cloud [144]

Answer:

a. 2x/3

b. 8

Explanation:

fundamental period can be defined to mean that at after every period of 2π radians or 360° the value of graph is repeated. For such functions the fundamental period is the period after which they repeat themselves.

It van also be looked as The fundamental period of cos(θ) is 2π. That is (for example) cos(0) to cos(2π) represents one full period.

Please see attachment for the step by step solution.

7 0
3 years ago
Other questions:
  • Methane gas at 25°C, 1 atm enters a reactor operating at steady-state and burns with 80% theoretical air entering at 227°C, 1 at
    10·1 answer
  • 1000 lb boulder B is resting on a 500 lb platform A when truck C accidentally accelerates to the right (truck in reverse). Which
    15·1 answer
  • Ammonia in a piston–cylinder assembly undergoes two processes in series. At the initial state, p1 = 120 lbf/in.2 and the quality
    15·1 answer
  • Is the MI-24 Hind the most widely exported combat helicopter in the world?
    14·1 answer
  • Who wanna learn C# for free tell me​
    10·1 answer
  • Dangerous of overloading in a circuit,​
    6·1 answer
  • 2) What kinds of food can you eat in space?
    14·2 answers
  • Motors are used to convert electrical energy into mechanical work and the output mechanical work of a motor is rated in horsepow
    9·1 answer
  • I feel so pressured..
    10·2 answers
  • 8. What are used by the project architect to depict different building systems and to show how they correlate to one anothe
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!