Question

In: Physics

What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std;...

What is the flowchart for this code. Thank You!

#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>

using namespace std;

float series(float r[], int n)
{
   float sum = 0;
   int i;
   for (i = 0; i < n; i++)
       sum += r[i];
   return sum;
}

float parallel(float r[], int n)
{
   float sum = 0;
   int i;
   for (i = 0; i < n; i++)
       sum = sum + (1 / r[i]);
   return 1 / sum;
}

int main()
{
   int n;
   cout << "Enter number of resistors: " << endl;
   cin >> n;
   float res[1000];
   cout << "Enter each resistor value: " << endl;
   int i;
   for (i = 0; i < n; i++)
       cin >> res[i];
   char respar;
   cout << "Are resistors in series (s) or parallel (p): " << endl;
   cin >> respar;

   if (respar == 's' || respar == 'S')
   {
       if (series(res, n) < 1000)
       {
           cout << "The total series resistance is: " << series(res, n) << " Ohms for " << n << " resistors." << endl;
           int i;
           for (i = 0; i < n; i++)
               cout << " " << res[i] << " Ohms" << endl;
       }
       else if (series(res, n) > 1000 && series(res, n) < 1000000)
       {
           cout << "The total series resistance is: " << series(res, n) / 1000 << " kOhms for " << n << " resistors." << endl;
           int i;
           for (i = 0; i < n; i++)
               cout << " " << res[i] << " Ohms" << endl;
       }
       else if (series(res, n) > 1000000)
       {
           cout << "The total series resistance is: " << series(res, n) / 1000000 << " MOhms for " << n << " resistors." << endl;
           int i;
           for (i = 0; i < n; i++)
               cout << " " << res[i] << " Ohms" << endl;
       }
   }
   else if (respar == 'p' || respar == 'P')
   {
       if (parallel(res, n) < 1000)
       {
           cout << "The total parallel resistance is: " << parallel(res, n) << " Ohms for " << n << " resistors." << endl;
           int i;
           for (i = 0; i < n; i++)
               cout << " " << res[i] << " Ohms" << endl;
       }
       else if (parallel(res, n) > 1000 && parallel(res, n) < 1000000)
       {
           cout << "The total parallel resistance is: " << parallel(res, n) / 1000 << " kOhms for " << n << " resistors." << endl;
           int i;
           for (i = 0; i < n; i++)
               cout << " " << res[i] << " Ohms" << endl;
       }
       else if (parallel(res, n) > 1000000)
       {
           cout << "The total parallel resistance is: " << parallel(res, n) / 1000000 << " MOhms for " << n << " resistors." << endl;
           int i;
           for (i = 0; i < n; i++)
               cout << " " << res[i] << " Ohms" << endl;
       }
   }
   int z;

   for (z = 0; z < n; z++)
   {
       if (res[z] == 0 && respar == 'p' || respar == 'P')
       {
           cout << "Parallel resistance is zero, there is a short circuit." << endl;
       }

   }
   return 0;


}

Solutions

Expert Solution


The flowchart for calculating whether resitors are in series or parallel and finding their sum.


Related Solutions

Can someone covert the code into C language #include<iostream> #include<iomanip> #include<ios> using namespace std; /******************************************************************************** Function...
Can someone covert the code into C language #include<iostream> #include<iomanip> #include<ios> using namespace std; /******************************************************************************** Function name: main Purpose:                   main function In parameters: b,r,i Out paramters: trun,error,total,value Version:                   1.0 Author: ********************************************************************************/ void main() {    int i;//declaring this variable to get value for quitting or calaculating series    do {//do while loop to calaculate series until user quits        cout << "Enter 1 to evaluate the series." << endl;       ...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class DivSales { private:    int quarterSales[4];    static double totalSales; public:    void add(int, int, int, int);    int sales(int);    static double getValue()    {        return totalSales;    };    void DivSales::add(int s1, int s2, int s3, int s4)    {        quarterSales[0] = s1;        quarterSales[1] = s2;        quarterSales[2] = s3;        quarterSales[3] = s4;...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count =...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count = 0, maximum = 0, minimum = 0;     cout << "Enter your student ID number: ";     cin >> studentid;     cout << "Student ID Number = " << studentid << endl;     while (studentid != 0)     {          numberreverse[count] = studentid % 10;          if (count == 0)          {              minimum = numberreverse[count];              maximum = minimum;          }          else...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput);...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput); // Declaring base int N = 30; if (userInput.length() > 10) { cout << 0 << endl; } else { int finalTotal = 0; //Iterates through userInput for(int i = 0; i < 10; i++){ char convertedInput = userInput[i]; // ASCII decimal value of each character int asciiDec = int(convertedInput); //Casts char value from input to int value stringstream chr; chr << convertedInput; int...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
In C++, assuming you have the following incomplete code: #include<iostream> #include <unistd.h> using namespace std; //...
In C++, assuming you have the following incomplete code: #include<iostream> #include <unistd.h> using namespace std; // Structure for storing the process data struct procData { char pname[5]; // Name of a process int arrivt; //Arrival time of a process int pburst; // Burst time of a process int endtime; // Exit time/ Leaving time of a process int remburst; // Remaining burst time of a process int readyFlag; // boolean, Flag for maintaining the process status }; // Global variable...
#include "IntVariableTable.h" #include "Tokens.h" #include <assert.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::left;...
#include "IntVariableTable.h" #include "Tokens.h" #include <assert.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::left; using std::right; using std::setw; using std::string; // The IntVariableTable constructor dynamically allocates the fixed size array of integer variables. IntVariableTable::IntVariableTable() { int_variable_table = new IntVariableEntry[MAX_INT_VARIABLES]; } // The IntVariableTable destructor deallocates the integer variable array. IntVariableTable::~IntVariableTable() { delete[] int_variable_table; } // Returns the number of variables added to the integer variable table. int IntVariableTable::numVariables() const { return num_int_variables; } // Returns the index of...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell {...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell { int val; Cell *next; }; int main() { int MAX = 10; Cell *c = NULL; Cell *HEAD = NULL; srand (time(NULL)); for (int i=0; i<MAX; i++) { // Use dynamic memory allocation to create a new Cell then initialize the // cell value (val) to rand(). Set the next pointer to the HEAD and // then update HEAD. } print_cells(HEAD); }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT