Question

In: Computer Science

USING C++ Create a program that defines a struct for a student. The following data should...

USING C++

Create a program that defines a struct for a student. The following data should be part of the struct: studentID (int), gpa(double), fullName(string), units(int).

Instantiate two students and have the user type in information for each, then print both back to the screen afterwards. Input validation: studentID should be positive and have 4 digits, GPA should be between 0 and 4 (inclusive), units should be positive. Have any invalid inputs reentered.

Solutions

Expert Solution

#include <iostream>

using namespace std;

struct Student{
   int studentID;
   double gpa;
   string fullName;
   int units;
};
struct Student getStudent(){
   Student s;
   int id,units;
   double gpa;
   string name;
  
   while(true){
       cout<<"Enter ID: ";
       cin>>id;
       if(id>=1000 && id<=9999)
           break;
       cout<<" Please Enter the ID between 1000 and 9999\n";
   }
   while(true){
       cout<<"Enter Gpa: ";
       cin>>gpa;
       if(gpa>=0 && gpa<=4)
           break;
       cout<<" Please Enter the GPA between 0 and 4\n";
   }
   cout<<"Enter name:";
   cin>>name;
   while(true){
       cout<<"Enter Gpa: ";
       cin>>units;
       if(units>=0)
           break;
       cout<<" Please Enter the Units greater than 0\n";
   }
   s.studentID=id;
   s.gpa=gpa;
   s.fullName=name;
   s.units=units;
   return s;
}
void display(Student &s){
   cout<<"ID: "<<s.studentID<<endl;
   cout<<"Name: "<<s.fullName<<endl;
   cout<<"GPA: "<<s.gpa<<endl;
   cout<<"Units: "<<s.units<<endl;
}

int main(){

   Student s1=getStudent();
   Student s2=getStudent();
   display(s1);
   display(s2);
  
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Create a C++ program that creates instances of a Struct using an Array (you can choose...
Create a C++ program that creates instances of a Struct using an Array (you can choose the number of instances to create). You can also use either user input or an initialization list to initialize 3 peoples names. Make sure that the values stored in each member are printed to the screen.
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
This project requires the student to create a record (in C++ called a struct). The record...
This project requires the student to create a record (in C++ called a struct). The record should contain several fields of different data types and should allow the user to search the records to find the student with the highest grade. In this project the student should gain an understanding of the nature of records with multiple data types, how to save the records, search the records and retrieve them.  The special problems of maintaining records of multiple data types on...
Create a structure In C program named Student with the following components and appropriate data types:...
Create a structure In C program named Student with the following components and appropriate data types: Name, ID, CGPA i. Create an Array of Students of size three and take user input to fill the array. ii. Now find the student with the least CGPA and display his or hers Name, ID and CGPA.
Create a struct for the following groups of data: (a) Product Data with the following members...
Create a struct for the following groups of data: (a) Product Data with the following members • ID • Name • Price • Quantity (b) Customer Data with the following members • ID • Name • Address • E-mail (c) Sales Data with the following members • Customer ID • Product IDs • Sale amount • Choose the types that you think will work best for the above descriptions. • Names should have a maximum size of 50. • Physical...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit:...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit: name (string, up to 50 characters long) color (string, up to 10 characters long) fat (integer) sugar (integer) carbohydrate (integer) Write a void function called printFruit that takes a fruitType parameter and prints the data (as shown in the example below). Declare a variable of type fruitType to store the following data: name: banana color: yellow fat: 1 sugar: 15 carbohydrate: 22 then use...
Create a C++ program that follows the specifications below: *Define a struct with 4 or more...
Create a C++ program that follows the specifications below: *Define a struct with 4 or more members. *Application must have at least one user-defined function *Declare an array of your struct using a size of 10 or more *Load the date for each element in your array from a text file *Display the data in your array in the terminal *provide brief comments for each line of code
Write a C program that creates a structure and displays its content. • Create a struct...
Write a C program that creates a structure and displays its content. • Create a struct that will be used to hold a student's name, age, and year in school (Freshman, Sophomore, Junior, or Senior) • Within function main, dynamically allocate space to hold the structure and assign a pointer to point to the memory space allocated • Read in (from the keyboard) the student's name, age, and year in school • Create a separate function with the prototype: void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT