1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Xelga [282]
3 years ago
9

p3_unzip :: [(a,b)] -> ([a], [b]) Write a function that takes a list of two-tuples and returns a tuple of two lists -- the fi

rst containing the first element of each tuple, and the second the second element (i.e., the reverse of "zip"). Examples: > p3_unzip [('a',1),('b',5),('c',8)] ("abc",[1,5,8])
Computers and Technology
1 answer:
klio [65]3 years ago
4 0

Answer:

<em>C++.</em>

Explanation:

#include <iostream>

#include<tuple>

using namespace std;

////////////////////////////////////////////////////////////

tuple<char*, int*> p3_unzip(tuple<char, int>* list, int count) {

   char* list1 = new char[count];

   int* list2 = new int[count];

   

   for (int i=0; i<count; i++) {

       tuple<char, int> temp = list[i];

       list1[i] = get<0>(temp);

       list2[i] = get<1>(temp);

   }

   

   tuple<char*, int*> new_tuple;

   get<0>(new_tuple) = list1;

   get<1>(new_tuple) = list2;

   

   return new_tuple;

}

int main() {

   tuple<char, int>* list;

   int count = 0;

   ////////////////////////////////////////

   cout<<"How many tuples? ";

   cin>>count;

   list = new tuple<char, int>[count];

   cout<<endl;

   

   char a;

   int b;

   tuple<char, int> temp;

   for (int i=0; i<count; i++) {

       cout<<"tuple "<<i+1<<" char: ";

       cin>>a;

       get<0>(temp) = a;

       

       cout<<"tuple "<<i+1<<" int: ";

       cin>>b;

       get<1>(temp) = b;

       

       list[i] = temp;

       cout<<endl;

   }

   ////////////////////////////////////////

   tuple<char*, int*> new_tuple = p3_unzip(list, count);

   char* list1 =  get<0>(new_tuple);

   int* list2 = get<1>(new_tuple);

   

   cout<<"Returned tuple:([";

   for (int i=0; i<count-1; i++) {

       cout<<list1[i]<<", ";

   }

   

   cout<<list1[count-1]<<"],[";

   

   for (int i=0; i<count-1; i++) {

       cout<<list2[i]<<", ";

   }

   

   cout<<list2[count-1]<<"])";

   ////////////////////////////////////////

   delete[] list, list1, list2;

   return 0;

}

You might be interested in
A ____ document identifies the purpose of the program being developed, the application title, the procedures to be followed when
telo118 [61]

Answer:

requirements

Explanation:

<h2><u>Fill in the blanks</u> </h2>

A <u>requirements</u> document identifies the purpose of the program being developed, the application title, the procedures to be followed when using the program, any equations and calculations required, any conditions within the program that must be tested, and any notes and restrictions that must be followed by the program.

7 0
3 years ago
Topic: Drivers ed 100 points and brainliest!
ddd [48]

Answer: Ill explain it!

Explanation: Modern technology is extremely beneficial to drivers because the modern cars have sensors that detect the range of other cars, when they stop and you might not see or be ready for it, your car will slam the brakes for you, this alone saves many lives. Another is like a Tesla with autopilot. Lets say for example one day your really sleepy or dont feel good, its a stress to keep the car straight. You could turn on autopilot and it could assist you with your driving, and their system has shown to be for the most part very beneficial and responsive. I would say another would be cameras above traffic lights watching for speeders and getting their license plates. This is important because people who are being risky and causing hazards on the road will get a fat ticket and will be seeing court. They are less likely to run a red light if they see a camera watching. I hope this helps you!

3 0
2 years ago
You should process the tokens by taking the first letter of every fifth word,starting with the first word in the file. Convert t
zhenek [66]

Answer:

See explaination

Explanation:

import java.io.File;

import java.io.IOException;

import java.util.Scanner;

import java.util.StringTokenizer;

public class SecretMessage {

public static void main(String[] args)throws IOException

{

File file = new File("secret.txt");

StringBuilder stringBuilder = new StringBuilder();

String str; char ch; int numberOfTokens = 1; // Changed the count to 1 as we already consider first workd as 1

if(file.exists())

{

Scanner inFile = new Scanner(file);

StringTokenizer line = new StringTokenizer(inFile.nextLine()); // Since the secret.txt file has only one line we dont need to loop through the file

ch = line.nextToken().toUpperCase().charAt(0); // Storing the first character of first word to string builder as mentioned in problem

stringBuilder = stringBuilder.append(ch);

while(line.hasMoreTokens()) { // Looping through each token of line read using Scanner.

str= line.nextToken();

numberOfTokens += 1; // Incrementing the numberOfTokens by one.

if(numberOfTokens == 5) { // Checking if it is the fifth word

ch = str.toUpperCase().charAt(0);

stringBuilder = stringBuilder.append(ch);

numberOfTokens =0;

}

}

System.out.println("----Secret Message----"+ stringBuilder);

}

}

}

5 0
3 years ago
Which software application offers a variety of templates for creating reports, flyers, and newsletters that you can access withi
dedylja [7]
D. Word processing software
3 0
3 years ago
What is the smartest person ever
Murljashka [212]

Answer: You!

Explanation: :D

7 0
3 years ago
Read 2 more answers
Other questions:
  • What is a geotag?
    10·1 answer
  • Which of the following definitions describes a chemical hazard?
    8·2 answers
  • William has an internet connection that does not allow him to make calls when connected to the internet. what internet service c
    7·2 answers
  • Why is brainly not working it say im logged out rn but im not i cant acces anything but this
    12·2 answers
  • pWhat macOS system application tracks each block on a volume to determine which blocks are in use and which ones are available t
    14·1 answer
  • The development of various technologies led to many historic events. Use information from the Internet to describe one major his
    7·1 answer
  • All of the following are advantages of database-stored information, except ______________. Multiple Choice
    7·1 answer
  • (Help please I don't know what to choose because it's both text and email but I can only pick one. HELP!!!!!!!!!!)
    6·2 answers
  • Which coding term means to carry out a series of steps one after another?
    7·2 answers
  • What is the benefit of hosting a website on a personali
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!