Question

#include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

#include <iostream>
using namespace std;

int main(void)
{
   int SIZE;
   cout<<"Enter the size of the array"<<endl;
   cin>>SIZE;

    int *numlist = new int[SIZE];

    // Read SIZE integers from the keyboard
    for (int i = 0; i<SIZE; i++ )
   {
       cout << "Enter value #" << i+1 << ": ";
       cin >> numlist[i];
    }
    // Display the numbers in a reverse order
    for (int i = SIZE; i > 0; i-- )
   {
       cout << "Value #" << i << ": ";
       cout << numlist[i-1] << endl; //Pay attention to i-1!
    }
   delete[] numlist;
   return 0;
}

Exercise 12.2
Define a class Student that has as its members the student_name and a student_ idnumber both of type string. Input from the keyboard the number of students in the database, then create a dynamic array of type Student and input the information for each student. Once you populate the database (stored all information), display the entire database. Remember to delete the dynamic array pointer before exiting the program.

C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

class Student

{

public:

string student_name;

int student_idnumber;

};

int main(void)

{

int n=0;

cout<<"enter the number of students : ";

cin>>n;

Student* student=new Student[n];

for(int i=0;i<n;i++)

{

cout<<"\nenter the name of student "<<i+1<<" : ";

cin>>student[i].student_name;

cout<<"\nenter the id of student "<<i+1<<" : ";

cin>>student[i].student_idnumber;

}

cout<<"\nThe list of students is:";

for(int i=0;i<n;i++)

{

cout<<"\nName : "<<student[i].student_name<<" , id : "<<student[i].student_idnumber;

}

delete[] student;

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
#include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This program illustrates dynamic variables #include <iostream> using namespace std; int main () {    int...

    This program illustrates dynamic variables #include <iostream> using namespace std; int main () {    int *p1;    p1 = new int;             // Variables created using the new operator are called dynamic variables    cout << "Enter an integer \n";    cin >> *p1;    *p1 = *p1 + 7;    cout << << "Your input + 7 = " << *p1 << endl;    delete p1;                // Delete the dynamic variable p1 and return the memory occupied by p1 to...

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main()...

    #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main() { int size = 10; int * A = newZeroArray(size); for(int i = 0; i < size; i++) cout << A[i] << " "; cout << endl; }Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...

  • #include <iostream> using namespace std; struct node { int base; int power; }; void insert(node ptr[],int...

    #include <iostream> using namespace std; struct node { int base; int power; }; void insert(node ptr[],int basee,int powerr) { ptr[powerr].power=powerr; ptr[powerr].base=basee; } void addition(node ptr1[],int size1,node ptr2[],int size2,node ptr3[],int size3) { for(int j=0;j<=size1;j++) { ptr3[j].base=ptr3[j].base+ptr1[j].base; } for(int j=0;j<=size2;j++) { ptr3[j].base=ptr3[j].base+ptr2[j].base; } } void display(node ptr[],int size) { if(ptr[0].base!=0) cout<<ptr[0].base<<"+"; for(int i=1; i<=size; i++) { if(ptr[i].base!=0) cout<<ptr[i].base<<"x^"<<ptr[i].power<<"+"; } } int main() { bool choice1=true; bool choice2=true; int size1,size2,base1,base2,power1,power2; cout<<"enter the max power in polynominal 1"; cin>>size1; node *a= new node[size1+1]; for(int...

  • Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int...

    Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int n; std::cin >> n; array a(n); for (int i = 0; i < n; i++) { std::cin >> a.data()[i]; } std::cout << "array size:" << a.max_size() << std::endl; std::cout << "array front:" << a.front() << std::endl; std::cout << "array back:" << a.back() << std::endl; int* data = a.data(); std::cout << "array elements using data:" << std::endl; for (int i = 0; i < n;...

  • C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; }...

    C++ #include <iostream> using namespace std; bool checkinventoryid(int id) {    return id > 0; } bool checkinventoryprice(float price) {    return price > 0; } void endProgram() {    system("pause");    exit(0); } void errorID(string str) {    cout << "Invalid Id!!! " << str << " should be greater than 0" << endl; } void errorPrice(string str) {    cout << "Invalid Price!!!" << str << " should be greater than 0" << endl; } int inputId() {...

  • #include <iostream> using namespace std; struct node { int base=0; int power=0; }; void insert(node ptr[],int...

    #include <iostream> using namespace std; struct node { int base=0; int power=0; }; void insert(node ptr[],int basee,int powerr) { ptr[powerr].power=powerr; ptr[powerr].base=basee; } void subtract(node ptr1[],int size1,node ptr2[],int size2,node ptr3[]) { for(int j=0;j<=size1;j++) { if(ptr1[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr1[j].base); ptr3[j].power=ptr2[j].power; } } for(int j=0;j<=size2;j++) { if(ptr2[j].base!=0) { ptr3[j].base=(ptr3[j].base)-(ptr2[j].base); ptr3[j].power=ptr2[j].power; } } } void addition(node ptr1[],int size1,node ptr2[],int size2,node ptr3[]) { for(int j=0;j<=size1;j++) { if(ptr1[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr1[j].base); ptr3[j].power=ptr2[j].power; } } for(int j=0;j<=size2;j++) { if(ptr2[j].base!=0) { ptr3[j].base=(ptr3[j].base)+(ptr2[j].base); ptr3[j].power=ptr2[j].power; } } } void display(node ptr[],int size)...

  • #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code...

    #include <iostream> using namespace std; bool binarySearch(int arr[], int start, int end, int target){ //your code here } void fill(int arr[], int count){ for(int i = 0; i < count; i++){ cout << "Enter number: "; cin >> arr[i]; } } void display(int arr[], int count){ for(int i = 0; i < count; i++){ cout << arr[i] << endl; } } int main() { cout << "How many items: "; int count; cin >> count; int * arr = new...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT