123456789101112131415161718192021222324252627282930313233343536373839
#include <iostream> using namespace std; const int N=2; struct Deg { int time; double deg; }; Deg getInfo(); int main(){ Deg t; t=getInfo(); for (int i=0; i<N; i++){ cout <<endl <<"Time "<<t.time<<endl <<"Degree: "<<t.deg<<endl; } cout<<endl; } Deg getInfo(){ Deg a; for (int i=0; i<N; i++){ cout <<"\nEnter time: "; cin>>a.time; cout<<"Enter the degree: "; cin>>a.deg; } return a; }
1234567891011
Deg getInfo(){ Deg a; for (int i=0; i<N; i++){ cout <<"\nEnter time: "; cin>>a.time; cout<<"Enter the degree: "; cin>>a.deg; } return a; }
time
deg
[code]Deg getInfo(){ Deg a; for (int i=0; i<N; i++){ cout <<"\nEnter time: "; cin>>a.time[i]; cout<<"Enter the degree: "; cin>>a.deg[i]; } return a; }
123456789
void getInfo( Deg a[] ){ for (int i=0; i<N; i++){ cout <<"\nEnter time: "; cin>>a[i].time; cout<<"Enter the degree: "; cin>>a[i].deg; } }
123456789101112131415161718192021
vector<Deg> getInfo() { vector<Deg> v; for (int i=0; i<N; i++) { Deg a; cout <<"\nEnter time: "; cin >> a.time; cout << "Enter the degree: "; cin >> a.deg; v.push_back(a); } return v; } int main() { for(const auto& t: getInfo()) { cout << '\n' << "Time " << t.time << '\n' << "Degree: " << t.deg << '\n'; } cout << '\n'; }