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
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...
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....
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...
Assign the correct CPT codes for each case study. Case Study # 1: Preoperative Diagnosis: Angina...
Assign the correct CPT codes for each case study. Case Study # 1: Preoperative Diagnosis: Angina Postoperative Diagnosis: Patent coronary arteries and grafts, ASHD present Procedure: Right and left heart cath with coronary angiography The patient was brought to the cath lab in a fasting state. The right going was prepped and draped in the usual sterile fashion. After local anesthesia was administered, sheaths were placed percutaneously into the right femoral artery and vein. IV heparin 3,000 units were given....
Production of desks: from Teak desk producers. Using excel. Table 1. Desk per desk Total costs...
Production of desks: from Teak desk producers. Using excel. Table 1. Desk per desk Total costs 0 1000 1 1500 2 1750 3 1850 4 2000 5 2200 6 2500 7 2900 8 3500 9 4200 10 5000 3a. Calculate short-run VC, FC, and MC for teak desk producers 3b. Calculate Atc, avc, and afc. 3c. Price of a desk=400.00 per desk. Calculate profit, calculate the shut-down point. 3d. Graph VC, FC, and MC 3e. Graph A TC, A VC,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT