#include <cstring>
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
const int SIZE = 20;
char str[SIZE];
char str1[SIZE];
int n;
int k =1;
printf("Enter a word: \n");
fgets(str,SIZE,stdin);
printf("Enter another word: \n");
fgets(str1,SIZE,stdin);
if (str1[strlen(str1) - 1] == '\n')
{
str1[strlen(str1)-1] =
'\0';
}
if (str[strlen(str) - 1] == '\n')
{
str[strlen(str)-1] =
'\0';
}
printf("Enter a number between 1 and 20:
\n");
scanf("%d",&n);
strcat(str, " ");
strncat(str, str1,n);
printf("%s", str);
printf("\n");
str[0] = toupper(str[0]);
for (int i = 1; i < strlen(str); i++)
{
str[i] =
tolower(str[i]);
if(str[i-1] == '
')
{
str[i]= toupper(str[i]);
}
}
for (int j = 1; j < strlen(str); j ++)
{
for (int i = 1; i <
strlen(str); i++)
{
//
if(str[i]!= '\0')
{
if(!strstr(str, "here"))
{
k++;
}
if(strchr(str,'\0'))
{
break;
}
}
}
}
cout << "Found "<< k << "
words 'here' in: \n" << str;
return 0;
}
================================================================================
so im practicing working on c++ with c-strings and i when i compile and run this, at the end the loop iterates one time for the entire length of the cstring and i cannot figure out how to end it after finding the 'k' amount of times the word "here" is in the string.
In: Computer Science
Python Coding Question (Data Science)
Hello I am having difficulty writing a code in python to do a specific task. I have two text files, Positive.txt and Practice_forhw1.txt. I want to write a script that will check if any words in Practice_forhw1.txt match any of the words in Positive.txt then the word would get replaced with a "+1" in the Practice_forhw1.txt and then print out the Practice_forhw1.txt. (i.e if the word "happy" is in both Positive.txt and Practice_forhw1.txt then I want the word "happy" to get replaced with a +1 in the Practice_forhw1.txt file.
My poor attempt below:
pos_file = open("Positive.txt", 'r')
#positive words are now in a list
pos_list = pos_file.readlines()
p_file = open("Practice_forhw1.txt", 'r')
p_list = p_file.readlines()
for word in p_list:
if word in p_list == word in pos_list:
word = word.replace(word, '+1')
print (word)
In: Computer Science
Using the Boyer-Moore algorithm, find the Bad Match table for the below patterns.
Pattern1: AABCACCCA
Pattern 2: CCCAAABBD
Pattern3: ABCABCBAD
Pattern4: BSDGSBAA
In: Computer Science
Need this in C++
// Start
// Declarations
// InputFile masterFile;
// InputFile transactionFile;
// OutputFile newMasterFile;
// num mClientNumber, mtotalClientCost, tClientNumber, titemClientCost
// string mClientfName, mClientlName// output "Master File Updating Starting"
// open masterFile "Master.rtf"
// open transactionFile "Transaction.rtf"
// open newMasterFile "newMaster.rtf"
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// read tClientNumber, titemClientCost from transactionFile
// while ( transactionFile not EOF )
// while (( masterFile not EOF) and (mClientNumber < tClientNumber))
// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// endwhile
// if (masterFile is EOF)
// output "Error Client ID: ", tClientNumber, " not in Master File."
// else if (mClientNumber == tClientNumber) then
// mtotalClientCost = mtotalClientCost + titemClientCost
// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// else if (mClientNumber > tClientNumber) then
// output "Error Client ID: ", tClientNumber, " not in Master File."
// endif
// read tClientNumber, titemClientCost from transactionFile
// endwhile
// while (masterFile not EOF)
// output mClientNumber, mClientfName, mClientlName, mtotalClientCost to newMasterFile
// read mClientNumber, mClientfName, mClientlName, mtotalClientCost from masterFile
// endwhile
// output "Master File Updating Complete"
// close masterFile
// close transactionFile
// close newMasterFile
// Stop
In: Computer Science
Write an HTML file that create the following web page.
my first nested list
steps of backing a cake
Important notes:
In: Computer Science
Consider the TA assignment problem where n Teaching
Assistants
(TAs) are to be assigned to n courses with one course having
exactly
one TA. Each course ranks all of the TAs, and each TA ranks all
the
courses, from most to least desirable.
Can you provide an example of an assignment and preference lists
such
that every TA and course forms an unstable pair? (Yes/No). If
Yes,
present the assignment. If No, justify your answer.
note: gale shapley algorithm
In: Computer Science
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds, and the priority given in integers (lower numbers represent higher priorities) :
Process Arrival Time Burst Time priority
P1 0 17 2
P2 5 8 3
P3 7 11 1
a. Draw Gantt charts illustrating the execution of these processes using nonpreemptive priority and preemptive priority, and Round Robins scheduling (time quantum = 4 ms).
b. What is the turnaround time of each process for each of the scheduling algorithms in part a?
In: Computer Science
In: Computer Science
SHOW WORK
Sort the given keys using Counting sort algorithm. Also write the algorithm.
5, 2, 3, 1, 0, 2, 1, 5, 0
SHOW WORK!
In: Computer Science
(Java Programming Problem)
Build two ArrayList lists from the Integer and String type arrays, populate the lists with repeats (see example below). Write a generic method (removeDuplicates( ….. )) to remove those duplicate items and returns an ArrayList<E> list without duplicates.
Original Integer List: [14, 24, 14, 42, 24, 25, 25, 23]
No-Duplicate List: [14, 24, 42, 25, 23]
Same generic method for the name list
Original List: [Mike, Lara, Jenny, Lara, Jared, Jonny, Lindsey, Mike, Jared]
No-Duplicate List: [Mike, Lara, Jenny, Jared, Jonny, Lindsey]
In: Computer Science
1. Write CREAT TABLE statements for the following tables (primary keys are underlined, foreign keys are in italic and bold). Make sure you have all needed constraints and appropriate datatypes for attributes:
Student (stID, stName, dateOfBirth, advID, majorName, GPA)
Advisor (advID, advName, specialty)
2. Insert several records in each table.
In: Computer Science
In Java, I need a program that will ask a user to input how many tests they want the average of. For example, It needs to ask the user how many tests would you like the average of? When the user enters the amount of tests they want the average score of, the program needs to give them that many test scores to input. Then with the average, determine what their grade is, if 90-100=A if 80-90 = B etc. Java and please explain.
In: Computer Science
Use C++
The ADT UnsortedType List function ‘DeleteItem(ItemType item)’ creates an endless loop error when trying to delete a word or key that is not in the list.
Example: Delete the word “letter” from the unsorted list.
Here are the lists contents before the DeleteItem(ItemType item) call:
super formula travel free thick Josephine Clara education
The question is ‘how can I exit gracefully from the DeleteItem(itemType Item) call when the word or key is not in the unsorted list and not get an endless loop but instead printing out a message that the word ‘letter’ is not in the loop? What code can be added?
void UnsortedType::DeleteItem(ItemType item)
{
NodeType* location;
NodeType* tempLocation;
location = listData;
if (item.ComparedTo(location->info) == EQUAL)
{
tempLocation = location;
listData = listData->next;
}
else
{
while (!((item.ComparedTo((location->next)->info) == EQUAL)))
location = location->next;
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
length--;
}
In: Computer Science
Suppose A and B are regular language. Prove that AB is regular
In: Computer Science