Changeset View
Changeset View
Standalone View
Standalone View
src/calculator/concCalculator.cpp
Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Line(s) | 278 | { | |||
---|---|---|---|---|---|
283 | switch (type) { | 283 | switch (type) { | ||
284 | case 0: //molarity specified | 284 | case 0: //molarity specified | ||
285 | // number of moles = volume * concentration | 285 | // number of moles = volume * concentration | ||
286 | numMoles = volumeSolvent() * m_concentration; | 286 | numMoles = volumeSolvent() * m_concentration; | ||
287 | break; | 287 | break; | ||
288 | case 1: // cannot be calculated (insufficient data) | 288 | case 1: // cannot be calculated (insufficient data) | ||
289 | error(INSUFFICIENT_DATA_MOLE); | 289 | error(INSUFFICIENT_DATA_MOLE); | ||
290 | return; | 290 | return; | ||
291 | break; | | |||
pino: ditto | |||||
292 | case 2: // molality specified | 291 | case 2: // molality specified | ||
293 | numMoles = massSolvent() / 1000.0 * m_concentration; | 292 | numMoles = massSolvent() / 1000.0 * m_concentration; | ||
294 | break; | 293 | break; | ||
295 | case 3: // cannot be calculated (insufficient data) | 294 | case 3: // cannot be calculated (insufficient data) | ||
296 | case 4: | 295 | case 4: | ||
297 | error(INSUFFICIENT_DATA_MOLE); | 296 | error(INSUFFICIENT_DATA_MOLE); | ||
298 | return; | 297 | return; | ||
299 | break; | | |||
pino: ditto | |||||
300 | case 5: // mole fraction specified | 298 | case 5: // mole fraction specified | ||
301 | numMoles = m_concentration / (100.0 - m_concentration) * molesSolvent(); | 299 | numMoles = m_concentration / (100.0 - m_concentration) * molesSolvent(); | ||
302 | break; | 300 | break; | ||
303 | } | 301 | } | ||
304 | 302 | | |||
305 | if (type2 == 2) { // amount of solute is specified in moles, cannot calculate | 303 | if (type2 == 2) { // amount of solute is specified in moles, cannot calculate | ||
306 | error(INSUFFICIENT_DATA_MOLES); | 304 | error(INSUFFICIENT_DATA_MOLES); | ||
307 | return; | 305 | return; | ||
Show All 15 Lines | 318 | { | |||
323 | int type2 = ui.amtSltType->currentIndex(); | 321 | int type2 = ui.amtSltType->currentIndex(); | ||
324 | 322 | | |||
325 | double numEqts; | 323 | double numEqts; | ||
326 | switch (type) { | 324 | switch (type) { | ||
327 | // Normality required | 325 | // Normality required | ||
328 | case 0: // molarity not sufficient | 326 | case 0: // molarity not sufficient | ||
329 | error(INSUFFICIENT_DATA_EQT); | 327 | error(INSUFFICIENT_DATA_EQT); | ||
330 | return; | 328 | return; | ||
331 | break; | | |||
pino: ditto | |||||
332 | case 1: // normality specified | 329 | case 1: // normality specified | ||
333 | numEqts = volumeSolvent() * m_concentration; | 330 | numEqts = volumeSolvent() * m_concentration; | ||
334 | break; | 331 | break; | ||
335 | case 2: | 332 | case 2: | ||
336 | case 3: | 333 | case 3: | ||
337 | case 4: | 334 | case 4: | ||
338 | case 5: | 335 | case 5: | ||
339 | error(INSUFFICIENT_DATA_EQT); | 336 | error(INSUFFICIENT_DATA_EQT); | ||
340 | return; | 337 | return; | ||
341 | break; | | |||
pino: ditto | |||||
342 | } | 338 | } | ||
343 | 339 | | |||
344 | if (type2 == 2) { // Amount of solute specified in moles, cannot calculate | 340 | if (type2 == 2) { // Amount of solute specified in moles, cannot calculate | ||
345 | error(INSUFFICIENT_DATA_MOLES); | 341 | error(INSUFFICIENT_DATA_MOLES); | ||
346 | } else { | 342 | } else { | ||
347 | if (numEqts == 0.0) { | 343 | if (numEqts == 0.0) { | ||
348 | error(EQTS_ZERO); | 344 | error(EQTS_ZERO); | ||
349 | return; | 345 | return; | ||
Show All 13 Lines | 355 | { | |||
363 | double numMoles; | 359 | double numMoles; | ||
364 | switch (type) { | 360 | switch (type) { | ||
365 | case 0: // molarity specified | 361 | case 0: // molarity specified | ||
366 | case 1: // normality specified | 362 | case 1: // normality specified | ||
367 | case 2: // molality specified | 363 | case 2: // molality specified | ||
368 | case 3: // mass fraction specified | 364 | case 3: // mass fraction specified | ||
369 | case 4: // volume fraction specified | 365 | case 4: // volume fraction specified | ||
370 | error(INSUFFICIENT_DATA_SOLVENT); | 366 | error(INSUFFICIENT_DATA_SOLVENT); | ||
371 | return; | 367 | return; // cannot be calculated (insufficient data) | ||
372 | break; // cannot be calculated (insufficient data) | | |||
pino: ditto | |||||
373 | case 5: // mole fraction specified | 368 | case 5: // mole fraction specified | ||
374 | numMoles = (100.0 - m_concentration) / m_concentration * molesSolute(); | 369 | numMoles = (100.0 - m_concentration) / m_concentration * molesSolute(); | ||
375 | break; | 370 | break; | ||
376 | } | 371 | } | ||
377 | 372 | | |||
378 | if (type2 == 2) { // amount specified in moles | 373 | if (type2 == 2) { // amount specified in moles | ||
379 | error(INSUFFICIENT_DATA_MOLES); | 374 | error(INSUFFICIENT_DATA_MOLES); | ||
380 | } else { | 375 | } else { | ||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Line(s) | 609 | { | |||
618 | case 0: | 613 | case 0: | ||
619 | volume = massSolute() / densitySolute(); | 614 | volume = massSolute() / densitySolute(); | ||
620 | break; | 615 | break; | ||
621 | case 1: | 616 | case 1: | ||
622 | volume = m_amtSolute.convertTo(KUnitConversion::Liter).number(); | 617 | volume = m_amtSolute.convertTo(KUnitConversion::Liter).number(); | ||
623 | break; | 618 | break; | ||
624 | case 2: | 619 | case 2: | ||
625 | volume = massSolute() / densitySolute(); | 620 | volume = massSolute() / densitySolute(); | ||
621 | break; | ||||
pino: ditto | |||||
626 | default: | 622 | default: | ||
627 | volume = 0; | 623 | volume = 0; | ||
628 | break; | 624 | break; | ||
629 | } | 625 | } | ||
630 | return volume; | 626 | return volume; | ||
631 | } | 627 | } | ||
632 | 628 | | |||
633 | double concCalculator::molesSolute() | 629 | double concCalculator::molesSolute() | ||
▲ Show 20 Lines • Show All 369 Lines • Show Last 20 Lines |
ditto