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.
CAN YOU CORRECT THIS CODE PLS. Scanner in = new Scanner (System.in);    // EXAMPLE 1...
CAN YOU CORRECT THIS CODE PLS. Scanner in = new Scanner (System.in);    // EXAMPLE 1 System.out.println("****************** EXAMPLE 1 *****************" ); int x = 4, y = 9; int a = 99, b = -22; if (x > y) System.out.println("x > y"); if (x < y) System.out.println("x < y"); if (x >= y) System.out.println("x >= y"); if (a <= 10023) System.out.println("a <= 10023"); if (b == y) System.out.println("b == y"); if (b == 5) System.out.println("b == 5"); if (x !=...
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...
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
Assign a new alphabet whenever it sees a new number in those expressions ( Use increment...
Assign a new alphabet whenever it sees a new number in those expressions ( Use increment operator(++) so, lets say if x = "a", then x++ would be "b" and so on for as many numbers are there in expressions) Assignment:Consider the input file “p4in.txt”has the following contents (in java language) (Assuming that all expressions are correct): so using the valueStack ,uses ArrayStack and operatorStack Specifications: 1) You must implement ArrayStack.java and modify Positfix.java so that valueStack uses ArrayStack and...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT