C++语言题目4

IT小小龙 posted @ 2014年4月06日 16:28 in C++ with tags 字典 , 609 阅读
//超市每天卖出的货物假如有egg,apple,pear三种,销售账目存储在了字典里,如下:
//account = [{"egg":[5.00, 3, "s"], 
//"apple":[2.50, 5, "s"], 
//"pear":[4.50, 2, "s"]},
//{"egg":[6.00, 3, "s"], 
//"apple":[3.00, 15, "q"], 
//"pear":[6.50, 2, "s"]},
//{"egg":[5.50, 5, "s"], 
//"apple":[3.50, 5, "s"], 
//"pear":[5.00, 6, "q"]},
//{"egg":[5.00, 3, "s"], 
//"apple":[2.50, 6, "s"], 
//"pear":[5.50, 2, "q"]},
//{"egg":[5.50, 8, "q"], 
//"apple":[3.50, 5, "s"], 
//"pear":[5.50, 3, "s"]}]
//每天的账目是列表中的一个元素,包括一个字典,字典的键是货物名称,字典的值的第一个元素是单价,
//第二个元素是数目,第三个元素,如果是s表示该账目没有任何疑问,如果是q表示该账目可能有错误。
//我们要做的是事情是统计每种货物,没有任何疑问的账目的销售总额。也就是对标志位为"s"的账目,
//按照货物名称,计算销售总额。(自己可根据使用的编程语言,确定存储结构,最后结果在屏幕打印
//egg、apple和pear分别的没有任何疑问的帐目的销售总额就可以。)
#include"iostream"
#include"string"
using namespace std;
class Account
{
private:
  string name;
  double price;
  float number;
  char flag;
public:
  Account(string goodsname, double goodsprice, float goodsnumber, char goodsflag)
  {
    name = goodsname;
    price = goodsprice;
    number = goodsnumber;
    flag = goodsflag;
  }
  double getTotalPrice()
  {
    return price*number; 
  }
  string getName()
  {
    return name;
  }
  char getFlag()
  {
    return flag;
  }
};
int main()
{
  Account accounts[15] = {
    Account("egg",5.00,3,'s'),
    Account("apple",2.50,5,'s'),
    Account("pear",4.50,2,'s'),
    Account("egg",6.00,3,'s'),
    Account("apple",3.00,15,'q'),
    Account("pear",6.50,2,'s'),
    Account("egg",5.50,5,'s'),
    Account("apple",3.50,5,'s'),
    Account("pear",5.00,6,'q'),
    Account("egg",5.00,3,'s'),
    Account("apple",2.50,6,'s'),
    Account("pear",5.50,2,'q'),
    Account("egg",5.50,8,'q'),
    Account("apple",3.50,5,'s'),
    Account("pear",5.50,3,'s')};
  string names[3] = {"egg", "apple", "pear"};
  int i=0;
  int j;
  double count=0;
  for(i=0; i<3; i++)
    {
      count = 0;
      for(j=0; j<15; j++)
	{
	  if((accounts[j].getName() == names[i]) && (accounts[j].getFlag() == 's'))
	    {
	      count = count + accounts[j].getTotalPrice();
	    }
	}
      cout<<names[i]<<"的总价是:"<<count<<endl;
    }
  return 1;
}
Avatar_small
HDFC Life Online Pay 说:
2022年8月06日 23:10

HDFC Life is one of the top insurance providers in India which helps many subscribers with their benefited plans, and customers get easy avenues that make their online payment and other options very easy, where HDFC was established in 2000 and it has been growing in service that it provides to customers. HDFC Life Online Payment The insurance policy through HDFC Life does carry in every different stream which ensures customers get their desired policy for their purpose, and customers can get more information about the HDFC Life Insurance from the official website of HDFC and here we will let you know how to get the installments for the policy to be paid.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter