d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ For Loop Assignment
Add Reply New Topic New Poll
Member
Posts: 17,302
Joined: Nov 25 2006
Gold: 23,806.60
Trader: Trusted
Sep 12 2013 06:40pm
Hey guys, I have a homework assignment due and my teacher doesn't teach us anything, I have no idea where to start.

If anyone can help I would really appreciate it, its due at midnight EST

HW2. Integrated Circuit Manufacturing -- for loop version

Using only the for construct for looping, devise code that computes the increase in size along a dimension of a growth medium off of an Integrated Circuit substrate. The growth rate equation to be used is: xt = x0 * (1+r)^t, where x0 is the initial value of x, xt is the value of x after time t, r is the percentage growth in a time period (seconds) and t is the time period. Note: '^' is not a valid C++ construct and must be calculated in another fashion (hint: x0 times t number of (1+r)'s).

Given variables:
1) char dopantType -- Input by user. Allowable options 'A', 'B', 'C', 'D', '0' for null
2) float stopTime -- Input by user. Allowable range is 10.0 to 200.0
3) float x0 -- Derived by program from user choice. Allowable range is 0.1 to 100.0
4) float rate -- Derived by program from user choice. Allowable range is 0.1 to 0.5
5) float xt -- Calculated by the program given the above equation.

The constraints to derive variables #3 and #4 are as follows:
-The values of x0 are the following for a given dopantType (dopantType,x0):
(A,0.1),(B,2.0),(C,4.0),(D,6.0),(0,0.0)
-The values of rate are the following for a given dopantType (dopantType,rate):
(A,0.1),(B,0.3),(C,0.2),(D,0.4),(0,0.0)

Using only the for construct for loops, develop code that performs the following tasks:
1) Read user inputs. Be sure to bounds check them for validity and if any are out of bounds print an error statement and loop until the inputs are valid.
2) Calculate derived variable.
3) Calculate xt at the stop time.
4) Print out all variables.
5) Print out if xt at stop time is greater than 20 or is less than or equal to 20

Be sure to test your code with the following input cases (assuming dopantType input first):
1) A 10
2) F G B 10
3) C 5 10
4) D 10
5) D 50
6) D 100
7) D 150
8) D 200




this is what I have right now, no idea if its right or not.

#include <iostream>
using namespace std;

int main ()
{

char dopantType = 0;
float stopTime = 0;
float x0 = 0;
float rate = 0;
float xt = 0;

switch(dopantType)
{
case 'A':
x0 = 0.1;
rate = 0.1;
break;

case 'B':
x0 = 2.0;
rate = 0.3;
break;

case 'C':
x0 = 4.0;
rate = 0.2;
break;

case 'D':
x0 = 6.0;
rate = 0.4;
break;

default:
x0 = 0.0;
rate = 0.0;
break;

}
}



Member
Posts: 6,192
Joined: Dec 13 2010
Gold: 6,669.99
Sep 12 2013 08:27pm
Well I guess I'll start it for you.
I did the first part of the question, the rest should be easy

Code
#include <iostream>
using namespace std;

int main ()
{

char dopantType = 0;
float stopTime = 0;
float x0 = 0;
float rate = 0;
float xt = 0;

while(dopantType == 0){ // do the loop until you have a valid character input from the problem
cin >> dopantType; // get user input

switch(dopantType)
{
case 'A':
x0 = 0.1;
rate = 0.1;
break;

case 'B':
x0 = 2.0;
rate = 0.3;
break;

case 'C':
x0 = 4.0;
rate = 0.2;
break;

case 'D':
x0 = 6.0;
rate = 0.4;
break;

case '0':
x0 = 0.0;
rate = 0.0;
break;

default:
 dopantType = 0; // return to while, get the input again.
 cout << "wrong input" << endl;
 } // end while
} // end switch

while( stopTime < 10.0 || stopTime > 200.0){ // do the loop if it's smaller than 10 or bigger than 200
 cin >> stopTime;
}

// put your code to calculate the other stuff here:


cout << dopantType  << endl << stopTime << endl << x0  << endl<< rate  << endl<< xt << endl; // displays all variables at the end
return 0;
}


This post was edited by ShadowFiend on Sep 12 2013 08:32pm
Member
Posts: 17,302
Joined: Nov 25 2006
Gold: 23,806.60
Trader: Trusted
Sep 15 2013 12:01pm
forgot to say thanks, been really busy this week. I appreciate the help, saved my grade
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll