62 523
Assignments Done
98,7%
Successfully Done
In June 2018

Answer to Question #24666 in C++ for alfred lontoc

Question #24666
For c++.

pls help me for my case study T_T

1. Write a program that will arrange the elements of 10-integer array in descending order. (descArray.cpp)

2.Write a program that will ask the name, age, address, and course of a student if the users typed yes. Otherwise, output all the inputted value. Create a function for the input, conditions, and display. (studentInfo.cpp)
Sample Run: Enter a name: Rose Ann
Enter age: 17
Enter address: Calamba, Laguna
Enter Course: BSCS
Do you want to enter another record [Y/N] ? Y

Enter a name: Rose Marie
Enter age: 19
Enter address: Cabuyao, Laguna
Enter Course: BSA
Do you want to enter another record [Y/N] ? Y

Enter a name: Rolando
Enter age: 16
Enter address: Makati City
Enter Course: BSCpE
Do you want to enter another record [Y/N] ? N

Expert's answer
//1

#include <ctime>
#include <cstdlib>
#include <iostream>

#include <conio.h>

const int ARRAY_SIZE = 10;

using namespace std;

void selection_sort(int* array, int arraySize)
{
& int maxIndex;
& int tmp;

& for (int i = 0; i < arraySize - 1; i++)
& {
maxIndex = i;
for (int j = i + 1; j < arraySize; j++)
if (array[j] > array[maxIndex])
& maxIndex = j;

tmp = array[maxIndex];
& array[maxIndex] = array[i];
array[i] = tmp;
& }
}

void fill_array(int* array, int array_size)
{
srand((int)time(NULL));
& for (int c = 0; c < array_size; c++)
array[c] = rand() % 50;
}

void print_array(int* array, int array_size)
{
& for (int c = 0; c < array_size; c++)
cout << array[c] << ' ';
& cout << endl;
}

int main(int argc, char *argv[])
{
int array[ARRAY_SIZE];
fill_array(array, ARRAY_SIZE);

cout << "The initial array:" << endl;
print_array(array, ARRAY_SIZE);
cout << endl;

selection_sort(array, ARRAY_SIZE);

cout << "Sorted array:" << endl;
print_array(array, ARRAY_SIZE);
cout << endl;

_getch();
return 0;
}


//2

#include <string>
#include <iostream>

#include <conio.h>

using namespace std;

struct Student
{
string name;
int age;
string address;
string course;
};

bool input_student_info(Student& s)
{
cout << endl;
cout << "Enter a name: ";
getline(cin, s.name);

cout << "Enter age: ";
cin >> s.age;
cin.sync();

cout << "Enter address: ";
getline(cin, s.address);

cout << "Enter Course: ";
getline(cin, s.course);

char choice;
cout << "Do you want to enter another record [Y/N] ? ";
cin >> choice;

cin.sync();
return (toupper(choice) == 'Y') ? true : false;
}

void display_student(Student& s)
{
cout << "Name: " << s.name << endl;
cout << "Age: " << s.age << endl;
cout << "Address: " << s.address << endl;
cout << "Course: " << s.course << endl << endl;
}

int main()
{
Student students[256];
int current = 0;

while (current < 256)
& if (!input_student_info(students[current++]))
& break;

cout << endl;
for (int s = 0; s < current; s++)
& display_student(students[s]);

_getch();
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

Assignment Expert
20.02.13, 17:35

You're welcome. We are glad to be helpful.
If you really liked our service please press like-button beside answer field. Thank you!

alfred lontoc
20.02.13, 17:32

THANK YOU FOR HELPING ME FOR MY STUDY CASE :))))
your such a good person!!

GODBLESS ALWAYS:)

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions