This Python script analyzes zip code data to identify sales agents and nearby zip codes within a specified distance. It extracts zip code data from a CSV file, calculates distances between agent zip codes and other zip codes, and outputs a CSV file with agent and nearby zip code details including distance. The script connects to an Oracle database to retrieve agent zip codes and details to include in the output.
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
C++ programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
C++ programming language notes for beginners and Collage students. Written for beginners. Colored graphics. Function by Function explanation with complete examples. Well commented examples. Illustrations are made available for data dealing at memory level.
i need help fixing my program so that the user can input both uper and.pdfshreeaadithyaacellso
i need help fixing my program so that the user can input both uper and lower case letters
Write a new C++ program named Vigerene.
use the rules of this website Code.org to return the message
Code.org (Links to an external site.)
Write the C++ program, Vigerene, which will prompt the user for a string message and a string
secret code. The code must be shorter than the message. Then write a function which takes the
message and code as parameters, and converts the two strings into a encrypted code using the
rules on the code.org website. Return the encrypted message and print it in the Main class.
Now write a new function which takes in an encrypted message and a secret code as two
parameters and decrypts the the message and returns it to Main for printing.
Here is sample output:
Enter your messge: my name is rick
Enter your secret code: helloworld
TBKYOHSQTVGVTNY
Enter your encrypted message
TBKYOHSQTVGVTNY
MY NAME IS RICK
code:
#include <iostream>
#include <string>
using namespace std;
string encrypt(string message, string code) {
string encrypted = "";
int j = 0;
for (int i = 0; i < message.length(); i++) {
char c = message[i];
if (isalpha(c)) {
int shift = code[j] - 'a';
char encrypted_char = (c + shift - 'a') % 26 + 'A';
encrypted += encrypted_char;
j = (j + 1) % code.length();
}
else {
encrypted += c;
}
}
return encrypted;
}
string decrypt(string message, string code) {
string decrypted = "";
int j = 0;
for (int i = 0; i < message.length(); i++) {
char c = message[i];
if (isalpha(c)) {
int shift = code[j] - 'a';
char decrypted_char = (c - shift - 'A' + 26) % 26 + 'A';
decrypted += decrypted_char;
j = (j + 1) % code.length();
}
else {
decrypted += c;
}
}
return decrypted;
}
int main() {
string message, code;
cout << "Enter your message: ";
getline(cin, message);
cout << "Enter your secret code: ";
getline(cin, code);
string encrypted = encrypt(message, code); // encrypt the message using the code
cout << "Encrypted message: " << encrypted << endl; // print the encrypted message
string decrypted = decrypt(encrypted, code); // decrypt the encrypted message using the code
cout << "Decrypted message: " << decrypted << endl; // print the decrypted message
cout << endl;
cout << "Enter your encrypted message: ";
getline(cin, encrypted);
decrypted = decrypt(encrypted, code);
cout << "Decrypted message: " << decrypted << endl;
return 0;
}
.
Need to make a flowchart for the following codepublic static voi.pdffaktdeal
Need to make a flowchart for the following code:
public static void main(String[] args) {
int num_cities;
double[][] city_coordinates;
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of cities: ");
num_cities = in.nextInt();
city_coordinates = new double[num_cities][2];
System.out.print("Enter the coordinates of the cities: ");
for (int i = 0; i < city_coordinates.length; i++) {
city_coordinates[i][0] = in.nextDouble();
city_coordinates[i][1] = in.nextDouble();
}
// Get the city with the smallest distance to the all other cities
double min_distance = Double.MAX_VALUE;
int min_index = 0;
for (int i = 0; i < city_coordinates.length; i++) {
double distance = 0;
for (int j = 0; j < city_coordinates.length; j++) {
if (i != j) {
distance += Math.sqrt(Math.pow(city_coordinates[i][0] - city_coordinates[j][0], 2)
+ Math.pow(city_coordinates[i][1] - city_coordinates[j][1], 2));
}
}
if (distance < min_distance) {
min_distance = distance;
min_index = i;
}
}
// Get total distance to all other cities
double total_distance = 0;
for (int i = 0; i < city_coordinates.length; i++) {
if (i != min_index) {
total_distance += Math.sqrt(Math.pow(city_coordinates[min_index][0] - city_coordinates[i][0],
2)
+ Math.pow(city_coordinates[min_index][1] - city_coordinates[i][1], 2));
}
}
System.out.printf("The central city is at (%.1f, %.1f)\n", city_coordinates[min_index][0],
city_coordinates[min_index][1]);
System.out.printf("The total distance to all other cities is %.2f\n", total_distance);
}
}.
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
We all do code reviews. Who doesn't admit this – does it twice as often. C++ code reviewers look like a sapper. .. except that they can make a mistake more than once. But sometimes the consequences are painful . Brave code review world.
Programming Fundamentals Arrays and Strings imtiazalijoono
Programming Fundamentals
Arrays and Strings
• Arrays
• Initializing arrays
• Multidimensional arrays
• Arrays as arguments to functions
• Strings
• String functions
Accessing Individual Components
Declaring Arrays
Arrays: Example Garbage
Multidimensional Arrays
1) Write a C program using arrays that produces the multiplication of two 2x2 matrices.
3-Dimensional Array
Write a program of your own choice that makes use of arrays of more than 2 dimensions.
2-Dimensional Arrays
A scrupulous code review - 15 bugs in C++ codePVS-Studio LLC
A close look at 15 problems one can find when reviewing C++ code.
Offers code examples.
Covers indexed loops, tainted data, copy and paste errors, problems with comparisons, exceptions, etc.
You can use static code analysis tools to make code review easier. Code analyzers find errors and potential vulnerabilities in code, while saving the developers' time and the companies' money.
Manual code review is expensive - a group of programmers get together regularly to review the code.
One can run static analysis tools regularly to find mistakes and vulnerabilities early.
2. else:
if (not lat1) or (not lon1) or (not lat2) or (not lon2):
return -1
lat1 = float(lat1) * math.pi/180
lon1 = float(lon1) * math.pi/180
lat2 = float(lat2) * math.pi/180
lon2 = float(lon2) * math.pi/180
return 3959.0 * math.acos(math.sin(lat1)*math.sin(lat2) +
math.cos(lat1)*math.cos(lat2)*math.cos(lon2-lon1))
#Above function changed from the following URL:
http://iamtgc.com/geocoding-with-python/ with the exception of the
#first if statement to check for the same zip code
try:
v_Cursor.execute(v_SQLStatementCreateTbl8)
v_Connection.commit()
except:
v_Cursor.execute(v_SQLStatementDropTbl8)
v_Cursor.execute(v_SQLStatementCreateTbl8)
v_Connection.commit()
v_Cursor.execute(v_SQLStatementSelectTbl8_1)
v_Connection.commit()
#get the Agt Data into an array
for results in v_Cursor.fetchall():
v_AgtZipCodeArray.append(results[0])
print v_AgtZipCodeArray
v_AllZipsFile = csv.DictReader(open(v_InputFile))
#read Zip code file into an array
for row in v_AllZipsFile:
v_ZipArray.append(row["Zipcode"])
v_ZipLatitude.append(row["Lat"])
v_ZipLongitude.append(row["Long"])
v_ZipCity.append(row["City"])
v_ZipState.append(row["State"])
#get the longitude and latitude of a zip code by looping through zip code
file
for i in range(len(v_AgtZipCodeArray)):
for j in range(len(v_ZipArray)):
if v_AgtZipCodeArray[i] == v_ZipArray[j]:
#Agent zip code [0], Agent Zip City [1], Agent Zip State [2],
Agent Latitude [3] , Agent Longitude [4]
v_ZipSets.append([v_AgtZipCodeArray[i] , v_ZipCity[j],
v_ZipState[j], v_ZipLatitude[j], v_ZipLongitude[j] ])
#get a list of zip codes from MIMs that are not in the zip code file.
for i in range(len(v_AgtZipCodeArray)):
InArray = v_AgtZipCodeArray[i] not in v_ZipArray
if InArray == True :
print v_AgtZipCodeArray[i]
#get the agent zipcodes and get the distances and if the distance is 30
miles or less then append to an array
# with detail
for i in range(len(v_ZipSets)):
3. for j in range(len(v_ZipArray)):
v_ZipDistance =
calculate_distance(v_ZipSets[i][3],v_ZipSets[i][4], v_ZipLatitude[j],
v_ZipLongitude[j])
#write zip code data for those zip codes that are equal to or
less than MaxDistance
#write zip code data for those zip codes are greater than -1
which is returned if one of the values is
#invalid in the function
if v_ZipDistance > -1 and v_ZipDistance <= v_MaxDistance :
#Agt zip code [0], Agt Zip City [1] , Agt Zip State [2], Agt
Latitude [3], Agt Longitude [4]
#Destination City, Destination State, Destination Zip Code,
Air Miles Distance
v_ZipSetsLess31.append([v_ZipSets[i][0], v_ZipSets[i][1],
v_ZipSets[i][2], v_ZipSets[i][3],
v_ZipSets[i][4], v_ZipCity[j],
v_ZipState[j], v_ZipArray[j],
v_ZipLatitude[j],
v_ZipLongitude[j],float(v_ZipDistance)] )
print v_ZipSetsLess31
v_Cursor.execute(v_SQLStatementSelectTbl8_2)
v_Connection.commit()
#get the employee service number for each origin zip to add
for results in v_Cursor.fetchall():
#employee service number [0], home zip code [1]
v_AgentDetailArray.append([results[0], results[1]])
#put the employee service number and add if the agent zip code matches
the origin zip code
for i in range(len(v_ZipSetsLess31)):
for j in range(len(v_AgentDetailArray)):
if v_ZipSetsLess31[i][0] == v_AgentDetailArray[j][1]:
v_ZipSetsLess31[i].append(v_AgentDetailArray[j][0])
v_OPF = open(v_OutputFile,'w')
for i in range(len(v_ZipSetsLess31)):
if counter == 1:
header = (["employee_service_number", "origin_zip_code",
"destination_zip_code", "distance"+"n" ])
v_OPF.write(','.join(header))
record = (v_ZipSetsLess31[i][11], v_ZipSetsLess31[i][0],
v_ZipSetsLess31[i][7],str(v_ZipSetsLess31[i][10])+'n')
counter = counter+1
v_OPF.write(','.join(record))
else:
record = (v_ZipSetsLess31[i][11], v_ZipSetsLess31[i][0],
v_ZipSetsLess31[i][7],str(v_ZipSetsLess31[i][10])+'n')
v_OPF.write(','.join(record))
v_OPF.close()