Brooklyn College C++ 作业!!

kimi876 2009-12-02 03:27:10
Write a program that will calculate the number of molecules of a substance given its
weight in grams and its molecular formula. Assume an unsorted file periodicTable.dat
that contains the atomic symbol, atomic number and mass number of several common
elements. For example the data file may contain the following lines:

H 1 1.0080
He 2 4.00260
C 6 12.011
N 7 14.0067
Na 11 22.9898
….
Create the file periodicTable.dat with a minimum of 25 elements.

Your program should ask the user to input the substance’s molecular formula and weight
and print the number of molecules. A typical dialogue would be:

Enter the molecular formula: CO2
Enter the weight in grams: 0.00220
The number of molecules in 0.00220 grams of CO2 is 3.01E19.
Enter the molecular formula: Fe2O3
….
Try your program on the following problems:
H2 5 grams
H2O 2.5 grams
Fe2O3 1 gram
C6H12O6 25 grams
Make up several more of your own. Be sure your program is clearly documented,
structured, and uses meaningful variables. Output is to be both to a file as well as to the
console. Turn in your program as well as input and output files.

Strategy 『方法』
1. Create a function readPeriodicTable that reads the information in the
periodicTable.dat file into three arrays: atomicSymbol, atomicNumber,
atomicMass. Your function should also return the number of elements in the
arrays.
2. Create a function bubbleSort that sorts the three arrays alphabetically.
3. Create a function printTable that prints a neatly formatted table of the information
that you have sorted.
4. The main function should prompt the user for the molecular formula and the
weight in grams.
5. The main function should call a function numberOfGramsPerMole which is given
the molecular formula as a parameter (string) and returns the number of grams per
mole. This function will have to parse the input string in order to separate each
element and the number of atoms of that element. Note the following rules:
a. An element always begins with a capital letter and may be followed by a
single lower case letter.
b. The absence of a number indicates a single atom of that element.

After determining the identity of the element and the number of atoms of that
element the function calls another function, findMassNumber in order to
determine the mass number of that element.
numberOfGramsPerMole then calculates, and eventually returns, the total number
of grams per mole represented by that formula.
6. The function findMassNumber receives a symbol of an element as a parameter
and returns its atomic mass by searching the arrays you created in steps 1 and 2. If
the element is not in the table, it should print an error message and return a value
which will allow the program to abort.
7. The main function then calls a function calculateNumberOfParticles that accepts
the weight in grams and the number of grams per mole as parameters and returns
the number of particles which is then printed by the main function.
8. The main function should repeat the process until the user indicates that there is
no more data to be processed.



简单得说就是输入化学式和其质量,然后计算其分子量
有能人看得明并且用getline 和 用count的方法 写个程序吗??(小弟只学到排列,其他的不会)

哪位高人能帮上小弟,我不会忘记他的!!
...全文
153 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kimi876 2009-12-02
  • 打赏
  • 举报
回复
re 1楼
好像没有这么简单 吧
WingForce 2009-12-02
  • 打赏
  • 举报
回复
Strategy 部分确实是。。。很严谨啊。。。。
WingForce 2009-12-02
  • 打赏
  • 举报
回复

#include <fstream>

using namespace std;

int main()
{
ifstream ifs("periodicTable.dat");

while (!ifs.eof())
{
string atomic_symbol;
int atomic_number;
double mass_number;
ifs >> atomic_symbol >> atomic_number >> mass_number;
cout << "Atomic: "
<< atomic_symbol << " "
<< atomic_number << " "
<< mass_number << endl;
}

ifs.close();
return 0;
}

内容概要:本文系统研究了基于雅可比伪逆迭代的双臂协同轨迹规划与跟踪误差收敛性问题,结合机械臂正向与逆向运动学建模、蒙特卡洛法分析工作空间、笛卡尔空间内的圆弧轨迹生成等关键技术,利用Matlab实现了双臂系统的协同控制与轨迹跟踪仿真。重点探讨了雅可比矩阵伪逆法在解决冗余自由度机械臂逆运动学问题中的应用,深入分析了轨迹跟踪过程中误差的收敛特性,并通过仿真实验验证了该方法在复杂任务场景下的有效性、稳定性与鲁棒性,为多臂机器人在工业自动化、精密操作等领域的协同作业提供了理论依据与技术支持。; 适合人群:具备机器人学、自动控制理论基础及Matlab编程能力的科研人员与工程技术人员,特别适合从事机械臂控制、轨迹规划、多机器人协同等方向的硕士、博士研究生及相关领域研究人员。; 使用场景及目标:①掌握基于雅可比伪逆法的机械臂逆运动学求解原理与实现方法;②理解双臂系统在笛卡尔空间中协同轨迹规划的机制;③分析并优化轨迹跟踪过程中的误差收敛性能;④为多机器人系统在复杂动态环境下的高精度协同控制提供算法设计与仿真验证支持。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,按照文档目录循序渐进地学习,重点关注算法实现细节、仿真参数设置与结果分析部分,同时可进一步探索将智能优化算法或深度学习方法引入轨迹规划与误差补偿的研究方向。

65,214

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧