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
vivado [14]
3 years ago
5

The major objective of this lab is to practice class and object-oriented programming (OOP), and separate files: 1. We will reuse

lab 6, a direct current simulator with extensions to let you practice OOP. Pay special attention to the difference between procedural programming and OOP. 2. This is the first time you break a program into several files such that you do not need to have all functions included in one program. The idea of breaking a program into several files has many benefits that will be explained in lecture notes and ZyBook reading assignment. It is NOT the purpose of this lab to train your logical thinking capability. We select a simple problem to help you fully understand OOP and separate files in an efficient manner.
Computers and Technology
1 answer:
vovangra [49]3 years ago
8 0

Answer:

Implementation of resistor.cpp

#include "resistor.h"

Ohms::Ohm()

{

// default constructor

voltage=0;

}

Ohms::Ohm( double x) // parameterised constructor

{

voltage = x; // voltage x set to the supply voltage in the private data field called voltage

}

Ohms:: setVoltage(double a)

{

voltage = a;// to set supply voltage in private data field called voltage

}

Ohms::setOneResistance( String s, double p)

{

cin>>p; //enter the resistance value

if(p<=0) // if resistance is less than or equals to 0

return false

else // if re

cin.getline(s);

}

Ohms::getVoltage()

{

return voltage; //return voltage of ckt

}

Ohms::getCurrent()

{

return current; //return current of ckt

}

Ohms:: getNode()

{

return resistors; //return resistors of ckt

}

Ohms::sumResist()

{

double tot_resist = accumulate(resistors.begin(),resistors.end(),0); //std::accumulate function for calculating sum //of vectors and following are the starting and ending points

return tot_resist;

}

Ohms::calcCurrent()

{

if(current <=0) // if current is less than or equal to 0

return false;

else   // if current is greater than 0

return true;

}

Ohms:: calcVoltageAcross()

{

if(voltage<=0) // if voltage is less than or equal to 0

return false;

else //if voltage greater than 0

return true;

}

Explanation:

in the case of main.cpp its simple just make a class object and remember to include resistors.cpp with it for which the second last picture describes the process precisely. (Hint: Use theunit test case functions in the main.cpp).

As you can see node is a structure consisting of member variables, followed by a class Ohms representing a DC circuit.

By looking at these pictures, it is needed to implement the main.cpp and resistor.cpp files. The user defined header file resistor.h already consists of all contents of Class Ohm, struct node. You don't need to modify it in anyway in such case.

You might be interested in
Question 7 (1 point)<br> Increasing hue levels means increasing saturation.<br> True<br> False
Temka [501]

Answer:

mae me brainlier

false

7 0
3 years ago
Write the one Sale method of the GroceryStore class. Method oneSale has one parameter: the name of one product (that a customer
DIA [1.3K]

Answer:

Check the explanation

Explanation:

bool oneSale(string item){

for(int i=0;i<capacity;i++){ // iterate till the capcity of array

if(item==grocerryList[i].name()){ // if name matches

 if(grocerryList[i].getStock()>0){ // and stock is greater than 0

  grocerryList[i].setStock(grocerryList[i].getStock()-1); // subtract 1 from the stock

// or alternate is grocerryList[i].stock= grocerryList[i].stock-1;

 return true; // return true

}

}

else if(item==grocerryList[i].name()){ // if name matches

 if(grocerryList.getStock()==0){ // but stock is empty

 return false; // return falsse

}

}

else{ // means item is not available so there is no need to check stock

return false; // return false

}

}

}

8 0
3 years ago
Write a function insert that takes an array of integers in ascending order, the number of integers currently in the array, the t
Andrei [34K]

Answer:

The code is written in MATLAB

function insert(array,integer,capacity,newInt)

if integer == capacity %if the array is full, the function returns the original array

result = array;

else

if newInt < array(1) %If the new integer is less than the first element, it copies the new integer as the new first element

array = [newInt array];

elseif newInt > array(end) %If the integer is greater than the last element, it copies the new integer as the new last element

array = [array newInt];

else %If the new integer is inside the array, then it checks its new place

for i = 1:length(array)-1

if array(i+1) > newInt % once the place of the new integer is found, the rest of the array is saved in a dummy array

dummy = array(i+1:end);

array(i+1) = newInt;

array(i+2:end) = '';%the rest of the array is deleted

array = [array dummy]; %concatanate the dummy array with the newInteger inserted array

break

end

end

end

end

fprintf('The inserted integer is %g\n', newInt);

fprintf('The new array is \n',array);

disp(array)

3 0
3 years ago
1. Write a shell script, renumber.sh, that will rename all the files in a directory. The first argument is a base name, second a
Scilla [17]

Answer:

#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ]

then

echo "invalid arguments"

exit 1

fi

filename="$1"

extension="$2"

cnt=1

for file in *. $extension

do

echo "renaming $file to $filename $cnt.$extension"

mv -i "$file" "$filename$cnt. $extension" #prompt before overwriting a file

cnt=$(( $cnt + 1 ))

done

Explanation:

6 0
4 years ago
What is a program that translates the information from the web server to a language like HTML into words and pictures that we ca
tresset_1 [31]
The answer is web browser
6 0
3 years ago
Other questions:
  • How many bits are in 1 tb? [hint: depending on the tool used to calculate this, you may need to use a trick to get the exact res
    6·1 answer
  • To apply a style to one or more elements on a web page, configure a css ________.
    5·1 answer
  • Which of the following is NOT a name of one of the central features of Facebook? Timeline Activity Log Graph Search Daily News
    11·1 answer
  • Which of these scenarios depicts unethical workplace practice by an employee?
    7·2 answers
  • By default, after how much time has elapsed in a client's DHCP lease will the client attempt to renew the lease?
    12·1 answer
  • Asymmetric key encryption combined with the information provided by a. certificate authority allows unique identification of the
    8·1 answer
  • Which statement describes Augmented Reality (AR) technology?
    12·1 answer
  • What is NOT a built-in function in python?<br> sqrt()<br> string()<br> fabs()<br> O print()
    12·2 answers
  • In Python, programmers use square brackets and an index range to slice multiple characters from a string.
    13·2 answers
  • Consider a file/directory with the following info:
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!