Софтуерно Инженерство
Loading...
Vankata83 avatar Vankata83 72 Точки

Task 5 Memory

Здравейте

Каква трябва да е сигнатурата на метода readCompaniesFromMemory в COMPANYMEMORYUTILS хедъра ?

Нещо съвсем се оплетох на тази задача :)

Този ред от мейна явно ме бърка: byte* memory = new byte[inputBytes.size()];

Ясно, че е заделяне на динамична памет, но не знам как точно да приема memory в метода.

 

Тагове:
0
C++ Advanced
Filipbg avatar Filipbg 26 Точки

Заповядай пример на функцията. Надявам се да е от полза 

#ifndef COMPANY_MEMORY_UTILS_H
#define COMPANY_MEMORY_UTILS_H

#include "Company.h"
using namespace std;

typedef unsigned char byte;

vector<Company> readCompaniesFromMemory(byte* memory, int numOfCompanies)
{
    vector<Company> allCompanies;
    for(int i = 0; i < numOfCompanies; ++i)
    {
        unsigned char idd = (*memory);
        int id = (int)idd;
        vector<char> namee;
        while(memory++)
        {
            if((*memory) != '\0' || (*memory) != 0)
                namee.push_back((*memory));
            else
                break;
        }
        string name;
        for(int k = 0; k < namee.size(); ++k)
		{
            name += namee[k];
		}
        ++memory;
        int numOfEmployees = (int)(*memory);
        vector<pair <char, char>> employeeNames;
        for(int k = 0; k < numOfEmployees; ++k)
        {
            ++memory;
            char first = toupper((*memory));
            ++memory;
            char second = toupper((*memory));
            employeeNames.push_back(pair <char, char> {first, second});
        }
        Company comp(id, name, employeeNames);
        allCompanies.push_back(comp);
        ++memory;
    }
    return allCompanies;
}
#endif // !COMPANY_MEMORY_UTILS_H

 

0
ThomasMore avatar ThomasMore -18 Точки

It proposes recognizing how to look at tremendous books inside a matter of an hour by methods for carefully assessing the summary of parts, examining and rehashing key territories and segments, and utilizing the subject once-over. On the off chance that you need to complete your organization, understand how to analyze. 

by: https://articleoftheweek.com/

-1