85.8k views
3 votes
Declare a structure whose tag name is Server and that contains the following fields: manufacturer, a string, model and serialnum, both also strings, year, an int, clockSpeed, a double, cores, an int, ram, an int and finally storage an int. In addition, declare a array named emp of 30 of these structures. Assign the value 12 to the last element of the arr field of the last element of emp. Assign 3.5 to the d field of the first emp element . Assign the string Hello to the k'th element of emp (assume k has been declared as an integer variable and assigned a value in the range of the array elements ).

1 Answer

5 votes

Answer:

Hi there Smartcreeper! You can declare structs in C++ to answer this question. Please refer to my explanation below.

Step-by-step explanation:

A struct in C++ allows us to define a structure with different data types into a single collection. The "emp[30];" at the end of the struct declares an array of the Server structure of size 30. The assignments to different components as required in the question are made and printed out to the console to verify.

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

struct Server {

string manufacturer;

string model;

string serialnum;

int year;

double clockSpeed;

int cores;

int ram;

int storage;

} emp[30];

int main()

{

int k = 5;

int d = 2;

emp[30].storage = 12;

emp[d].manufacturer = 3.50;

emp[k].model = "Hello";

cout << emp[30].storage << endl;

cout << emp[d].manufacturer << endl;

cout << emp[k].model << endl;

}

User Amenthes
by
5.5k points