Question

In: Computer Science

Use psuedo-code for the following: 1) Assign a new student into the correct desk in a...

Use psuedo-code for the following:

1) Assign a new student into the correct desk in a room of students seated in alphabetical order. (Sort by just last name)

Solutions

Expert Solution

Here is the pseudocode for doing the above task:

Ask for the number of students in the class, let it be n
string array studs[n] to hold n students
for i=0 to n:
        input studs[i] in format lastname<space>firstname
Now apply bubble sort to the list of students
for i=0 to n-1:
        for j=0 to n-i-1:
                if studs[j]>studs[j+1] alphabetically:
                        swap(studs[j],studs[j+1])
print students according to the seat numbers
for i=0 to n:
        print: seat i - studs[i]

Here is a c++ program to do that:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int n, i, j;
    cout << "Enter number of students: ";
    cin >> n;
    getchar();
    string studs[n];
    cout << "Enter " << n << " students name (lastname, firstname)\n";
    for (i = 0; i < n; i++)
        getline(cin, studs[i]);
    for (i = 0; i < n - 1; i++)
        for (j = 0; j < n - i - 1; j++)
            if (studs[j] > studs[j + 1])
            {
                string temp;
                temp = studs[j];
                studs[j] = studs[j + 1];
                studs[j + 1] = temp;
            }
    for (i = 0; i < n; i++)
    {
        cout << "Seat " << i + 1 << " - " << studs[i] << "\n";
    }
    return 0;
}

Here is the output of above code:


Related Solutions

Answer the following questions thoroughly. Use correct grammar and punctuation. 1) A student observes the following...
Answer the following questions thoroughly. Use correct grammar and punctuation. 1) A student observes the following spinner and claims that the color red has the highest probability of appearing, since there are two red areas on the spinner. What is your reply? Your answers should include facts, rules, any definitions necessary to explain why the student is correct or incorrect. 2) In class, an experiment of flipping a coin is performed. Pretend that you are introducing the concept of probability...
Answer the following questions thoroughly. Use correct grammar and punctuation. 1) A student observes the following...
Answer the following questions thoroughly. Use correct grammar and punctuation. 1) A student observes the following spinner and claims that the color red has the highest probability of appearing, since there are two red areas on the spinner. What is your reply? Your answers should include facts, rules, any definitions necessary to explain why the student is correct or incorrect. 2) In class, an experiment of flipping a coin is performed. Pretend that you are introducing the concept of probability...
HOW TO CODE AND SEQUENCE THE FOLLOWING: 1.ASSESSMENT: DKA, TYPE 1DM Tip: ASSIGN A SECOND CODE...
HOW TO CODE AND SEQUENCE THE FOLLOWING: 1.ASSESSMENT: DKA, TYPE 1DM Tip: ASSIGN A SECOND CODE FOR UNDERDOSING OF INSULIN FROM THE TABLE OF DRUGS AND CHEMICALS. 2. ASSESSMENT: TEST RESULTS SHOW ABNORMALLY LOW VITAMIN D LEVEL. PATIENT IS OBESE DUE TO EXCESS CALORIES AND HAS A (BMI) OF 30.5 KG/M2 TIP: Z CODE FOR ANNUAL CHECKUP IS NEEDED.
Develop the pseudo code for, desk check and test the following programs. Allow the user to...
Develop the pseudo code for, desk check and test the following programs. Allow the user to provide the number of elements, and initialise the array according to their input. Use functions where appropriate to ensure modularity. 1. Find the average of a list of numbers 2. Find the smallest element in a list of numbers
1.A pharmaceutical company is testing their new nicotine patch. They randomly assign 100 volunteers to use...
1.A pharmaceutical company is testing their new nicotine patch. They randomly assign 100 volunteers to use the patch and finding that 37 had quit smoking after 8 weeks. Compute the 96% confidence interval. You DO need to check CLT here. 2.For # 32 .In the United States, the population mean height for 3-year-old boys is 38 inches. Suppose a random sample of 30 non-U.S. 3-year-old boys showed a sample mean of 37.2 inches with a standard deviation of 3 inches....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1. You must call all of the defined functions above in your code. You may not change function names, parameters, or return types. 2. You must use a switch statement to check the user's menu option choice. 3. You may create additional functions in addition to the required functions listed above if you would like. 4. If user provides option which is not a choice...
check the following code: is the requirements correct ? if not solve it . All the...
check the following code: is the requirements correct ? if not solve it . All the styles must be in a document style sheet. YOU ARE NOT ALLOWED TO USE THE type ATTRIBUTE ON THE LIST, you must use CSS to apply the style. <!DOCTYPE html> <html> <head> <title> car list</title> <style> body {background-color: powderblue;} h1   {color: blue;} p    {color: red;} </style> </head> <body> <style type="text/css"> ol{list-style-type:upper-roman;} ol ol{list-style-type:upper-alpha;} ol ol ol{list-style-type:decimal;} li.compact{background-color:pink;} li.midsize{background-color:blue;} li.sports{background- color:red;} ol.compact{background-color:pink;} ol.midsize{background-color:blue;} ol.sports{background-color:red;} </style>...
Assign the correct ICD-10-AM/ACHI codes to the following: 1- This23-year-old female was admitted at 38 weeks...
Assign the correct ICD-10-AM/ACHI codes to the following: 1- This23-year-old female was admitted at 38 weeks gestation for induction of labor due to mild pre-eclampsia. The patient failed to dilate during medical induction. The decision was made to perform a cesarean section due to failed induction. The fetus was found to be in compound position. 2- Pregnancy delivered, single liveborn, vaginal delivery following prolonged first stage of labor, 38 weeks of gestation. 3- The patient is seen in the ED...
Complete the following in syntactically correct Python code. 1. The program should display a message indicating...
Complete the following in syntactically correct Python code. 1. The program should display a message indicating whether the person is an infant, a child, a teenager, or an adult. Following are the guidelines: a. If the person is older than 1 year old or less, he or she is an infant. b. If the person is older than 1 year, but younger than 13, he or she is a child c. If the person is at least 13 years old,...
The following is the original code, (add, t1, 3, 5) (assign, a, t1) (add, t2, 3,...
The following is the original code, (add, t1, 3, 5) (assign, a, t1) (add, t2, 3, 5) (sub, t3, t2, z) (assign, b, t3) Constant folding is applied to give the following, (assign, t1, 8) (assign, a, t1) (assign, t2, 8) (sub, t3, t2, z) (assign, b, t3) After the constant folding is applied, the (assign, t2, 8) becomes redundant. What optimizations should take place in order to remove this redundancy in the constant folded code? Also show the optimized...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT