Answer to Question #279097 in C++ for Anna mae

Question #279097

Write a program that lists 30 employees' names, their jobs, and the store where they work using a two-dimensional array.


1
Expert's answer
2021-12-13T16:58:03-0500
#include <iostream>
#include "string"

struct Info{
    std::string first, second;
    Info(){
        static bool isWorker = true;
        std::cout<<(isWorker?"First and second name: \n ":"Place: \n ");
        std::cin>>first;
        std::cout<<(isWorker?"":"Job: \n ");
        std::cin>>second;
        isWorker = !isWorker;
    }
    ~Info() {
        static bool isWorker = true;
        std::cout<<(isWorker?"First name: ":"Place: ")<<first<<" ";
        std::cout<<(isWorker?"Second name: ":"Job: ")<<second<<" ";
        std::cout<<(isWorker?"- ":"\n");
        isWorker = !isWorker;
    }
};

int main() {
    Info data[30][2]{};
    while(std::cin.fail()){
        int x;
        std::cout<<"\nNumber of Employer: ";
        std::cin>>x;
        if(x>30||x<1)
            continue;
        --x;
        std::cout<<"\nFirst name: "<<data[x][0].first<<"\nSecond name: "<<data[x][0].second;
        std::cout<<"\nPlace: "<<data[x][1].first<<"\nJob: "<<data[x][1].second;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog