C++.how to write a selection sort to sort it.
read_book_data()
This member function takes one parameter, a string that contains the name of a file. This string parameter can be a C++ string or a C string (your choice). The function returns nothing.
This constructor should do the following:
Declare and open an input file stream variable using the file name string passed in as a parameter.
Check to make sure the file was opened successfully. If not, print an error message and exit the program.
Read the file into your book_store object using the ifstream::read() member function for binary input.
Close the file stream variable.
Sort the book objects in the array in ascending order by ISBN number using a sorting algorithm of your choice. Note that the ISBNs are C strings, which means that you will not be able to compare them using the standard relational operators. The ISBN is also private data of the book class, so code in the book_store class will need to call get_isbn() for book object rather than accessing the object's ISBN directly.
Note that the code described above will read data into all of the book data members. That includes both the array of 30 book objects, and the number of array elements filled with valid data. No further initialization of the data members will be needed
void book_store::read_book_data(string data)
{
ifstream inFile;
inFile.open(data, ios::binary);
if( inFile.fail() )
{
cout << "input file did not open";
exit(-1);
}
inFile.read((char*)this, sizeof(book_store));
inFile.close();
}
C++.how to write a selection sort to sort it.
In: Computer Science
In: Computer Science
Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have to implement a small intentional bug in your program and post it for other students to debug.
To be able to receive your full discussion points, you need to submit the following.
Following is your check list and rubric
Attach your .cpp file/s with an
implemented bug - 20pnts
Describe what the code does in
detail - 20pnts
Debug at least one other program and
submit your .cpp file - 40pnts (note what the bug was in
comments)
After running the debugged program,
attach the screen shot of your output- 20pnts
// This program uses a function that returns a value.
#include <iostream>
using namespace std;
// Function prototype
int sum(int num1, int num2);
int main()
{
int value1 = 20, // The first value
value2 = 40, //
The second value
total; // Holds the
returned total
// Call the sum function, passing the contents
of
// value1 and value2 as arguments. Assign the
return
// value to the total variable.
total = sum(value1, value2);
// Display the sum of the values
cout << "The sum of " << value1 << "
and "
<< value2 <<
" is " << total << endl;
return 0;
}
/*********************************************************
*
sum
*
* This function returns the sum of its two parameters. *
*********************************************************/
int sum(int num1, int num2)
{
return num1 + num2;
}
In: Computer Science
Assignment 3 Note:
Tables referred in this assignment are same as that of Assignment 2.
1. For each table, append your student id along with the table name. For e.g. employee_student id (employee_T16363737)
2. Format for questions: a. Question: b. SQL statement solution c. Screenshot for correct input d. Screenshot for violation (if any)
Q1) Check the structure of tables.
Q2) Check the constraint name for applied constraints?
Q3) Drop the unique constraint on ENAME
Q4) Drop the Foreign Key constraint on DEPTNO
Q5) Add Foreign Key constraint on DEPTNO
Q6) Change Data type of ENAME. (If previously you have marked it as VARCHAR 2, then make it CHAR or vice versa)
Q7) Change width of DNAME ( For e.g. If you have defined it’s size has 20 then make it 30)
Q8) Add COMM column in EMP table
Q9) Drop CITY column from S table
Q10) Create duplicate copy of EMP table
Q11) Copy structure of DEPT table in another table with different column names
Q12) Change the name and job of the employee whose EMPNO =100
Q13) Delete the record of employee who belong to computer department
Q14) Drop DEPT Table
Q15) Drop duplicate table of EMP table
In: Computer Science
Programming Assignment 1: Representing, Managing and Manipulating Travel Options
You may NOT do any of the following:
change any of the function names or signatures (parameter lists and types and return type)
introduce any global or static variables
use any arrays or vectors inside the TravelOptions class! Not for this assignment!! (You may use them as you see fit in any driver/tester programs you write)
You MAY do any of the following as you see fit:
Introduce helper functions. But you should make them private.
Reminders:
Some functions eliminate list entries (e.g., prune_sorted). Don't
forget to deallocate the associated nodes (using the delete
operator).
Please read the below code and complete the missing parts.
#ifndef _TRVL_OPTNS_H
#define _TRVL_OPTNS_H
#include <iostream>
#include <vector>
#include <utility>
// using namespace std;
class TravelOptions{
public:
enum Relationship { better, worse, equal, incomparable};
private:
struct Node {
double price;
double time;
Node *next;
Node(double _price=0, double _time=0, Node* _next=nullptr){
price = _price; time = _time; next = _next;
}
};
/* TravelOptions private data members */
Node *front; // pointer for first node in linked list (or null if list is empty)
int _size;
public:
// constructors
TravelOptions() {
front = nullptr;
_size=0;
}
~TravelOptions( ) {
clear();
}
/**
* func: clear
* desc: Deletes all Nodes currently in the list
* status: DONE
*/
void clear(){
Node *p, *pnxt;
p = front;
while(p != nullptr) {
pnxt = p->next;
delete p;
p = pnxt;
}
_size = 0;
front = nullptr;
}
/**
* func: size
* desc: returns the number of elements in the list
* status: DONE
*/
int size( ) const {
return _size;
}
/**
* func: compare
* desc: compares option A (priceA, timeA) with option B (priceB, timeA) and
* returns result (see enum Relationship above):
*
* There are four possible scenarios:
* - A and B are identical: option A and option B have identical price and time:
* ACTION: return equal
* - A is better than B: option A and B are NOT equal/identical AND
* option A is no more expensive than option B AND
* option A is no slower than option B
* ACTION: return better
* - A is worse than B: option A and B are NOT equal/identical AND
* option A is at least as expensive as option B AND
* option A is no faster than option B
* ACTION: return worse
* NOTE: this means B is better than A
* - A and B are incomparable: everything else: one option is cheaper and
* the other is faster.
* ACTION: return incomparable
*
* COMMENTS: since this is a static function, there is no calling object.
* To call it from a client program, you would do something like this:
*
TravelOptions::Relationship r;
double pa, ta, pb, tb;
// some code to set the four price/time variables
r = TravelOptions::compare(pa, ta, pb, tb);
if(r == TravelOptions::better)
std::cout << "looks like option b is useless!" << std::endl;
// etcetera
*
* status: TODO
*/
static Relationship compare(double priceA, double timeA,
double priceB, double timeB) {
return incomparable; // placeholder
}
In: Computer Science
Python , no strings, len(), or indexing
Write the function setKthDigit(n, k, d) that takes three
# non-negative integers -- n, k, and d -- where d is a single
digit
# (between 0 and 9 inclusive), and returns the number n but
with
# the kth digit replaced with d. Counting starts at 0 and
goes
# right-to-left, so the 0th digit is the rightmost digit.
In: Computer Science
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned integer numbers // 123, 007, 4567890, etc. Show: Finite Automaton Definition, Graph, Table.
In: Computer Science
- Create a java class named SaveFile in which write the following:
Constructor: The class's constructor should take the name of a file as an argument
A method save (String line): This method should open the file defined by the constructor, save the string value of line at the end of the file, and then close the file.
- In the same package create a new Java class and it DisplayFile in which write the following:
Constructor: The class's constructor should take the name of a file as an argument
A method display(): This method should check if the file defined by the constructor exist or not, if the file does not exist it displays the message "The file does not exists" and then exit the program, however if the file exists it displays the file contents line by line into the screen, and then close the file.
A method display (int n): This method is similar to display () but it displays the first n number of lines of the file's contents only. If the file contains less than n lines, it should display the file's entire contents.
A method display (int from, int to): This method is similar to display() but it displays the files's contents starting from line number from to the line number to. If the file contains less than to lines, it should display the file's contents. Note that, from is always less than to.
- In the same package, create another class called FilesDemo, in it's main method do the following:
create an instance of the class SaveFile to create new file named "lines.txt"
print the following lines into the file:
1-Lorem ipsum dolor sit amet
2-Consectetuer adipiscing elit
3-Sed diam nonummy nibh euismod tincidunt
4-Ut wisi enim ad minim veniam
5-Quis nostrud exerci tation ullamcorper
6-Suscipit lobortis nisl ut aliquip ex ea commodo consequat
7-Duis autem vel eum iriure dolor in hendrerit
8-Vel illum dolore eu feugiat nulla facilisis at vero eros
Create an instance of the class DisplayFile to open "lines.txt"
using this instance invoke the method display()
using this instance invoke the method display(3) and display(10)
using this instance invoke the method display(3, 5)
Run your program and make sure it prints the correct output.
In: Computer Science
10) Create a java program that will ask for name and age with method age where it will check the condition that id you are greater than 18 you can vote.
In: Computer Science
11) Enter the following using Java.
Use for loop to enter student id, student name, major and grades. Also grades should display their letter grades based on their conditions.
After that display the name of students and their info, and also their letter grade
After that display the sum of all grades and the average
Output Example:
Student ID: 0957644
Student Name: Pedro Hernandez
Student Major: Business Information Systems
Grades for Fall 2020:
Introduction to Computer Science using Java: 85, B
Statistics: 85, B
Introduction to Psychology: 92, A
English Composition II: 84, B
Sum = 346
Average= 86.5, B
In: Computer Science
Modify the code below to support specifying additional dice type in addition to a 6 sided dice.
For example, the program could support six-sided, eight-sided, 10 sided die.
HINTS: You will need to
Think about parameter passing. It is possible to do this with a very few modifications to the program.
//Program: Roll dice
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int rollDice(int num);
int main()
{
cout << "The number of times the dice are rolled to "
<< "get the sum 10 = " << rollDice(10) <<
endl;
cout << "The number of times the dice are rolled to "
<< "get the sum 6 = " << rollDice(6) << endl;
return 0;
}
int rollDice(int num)
{
int die1;
int die2;
int sum;
int rollCount = 0;
srand(time(0));
do
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
sum = die1 + die2;
rollCount++;
}
while (sum != num);
return rollCount;
}
In: Computer Science
Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide:
• Number of days on the trip
• Amount of airfare, if any
• Amount of car rental fees, if any
• Number of miles driven, if a private vehicle was used
• Amount of parking fees, if any
• Amount of taxi charges, if any
• Conference or seminar registration fees, if any
• Lodging charges, per night
The company reimburses travel expenses according to the following policy:
• $37 per day for meals
• Parking fees, up to $10.00 per day
• Taxi charges up to $20.00 per day
• Lodging charges up to $95.00 per day
• If a private vehicle is used, $0.27 per mile driven.
The application should calculate and display the following:
• Total expenses incurred by the businessperson
• The total allowable expenses for the trip
• The excess that must be paid by the businessperson, if any
• The amount saved by the businessperson if the expenses were under the total allowed
In: Computer Science
q1)
Critically assess how the computer monitor image differs from a television image and analyse the limitations in creating images on the computer destined for a television screen
In: Computer Science
1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25 keys. Do you expect to see any collisions? Why or why not?
Yes, because random values likely will land on same locations. |
No becase there are four times as many slots as needed. |
2. Secondary clustering means that elements that hash to the
same position will probe to the same alternate cells.
Simple hashing uses key%tablesize as the hash function.
Which of the following sequence of insertions would demonstrate secondary clustering of quadratic probing if the tablesize is 100?
1,3,5,7,9 |
Secondary clustering is unlikely with quadratic probing. |
1,2,3,4,5,6 |
259,359,459,559 |
0,1,4,9,16,25,36,49 |
3.Using double hashing (as the Collision Resolution technique), consider inserting multiple copies of the same value Is there clustering?
The table is large enough there is little chance for collision. |
Because neighbors are not used for overflow, clustering does not occur. |
Each key has a unique step function. |
There is clustering. It is impossible to prevent. |
4. Consider the following collision resolution scheme: You use linear probing, but always increment by 3 (rather than 1) in the event of a collision.
Which is true of this method?
secondary clustering |
non-clustering |
primary clustering |
In: Computer Science
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average field by dividing points by credit hours earned. Write methods to display the values in each Student field. Save this class as Student.java.
In: Computer Science