How do I take each line from a text file and average them?

I have a problem where I have to read in a text file. Take each line of numbers, average the numbers, and then push those numbers to a vector.

70 79 72 78 71 73 68 74 75 70

78 89 96 91 94 95 92 88 95 92

83 81 93 85 84 79 78 90 88 79

This is only some of the file. I don’t know how to put all of it, I am sure it is not necessary.

I have successfully opened the file. I have looked everywhere online about how to read in each line and try to average the numbers. However I have always ended up unsuccessful in doing that. I am a beginner to C++ so I am very sorry for not knowing much.

int main() {     string inFileName = "lab1.txt";     ifstream inFile;     vector<string> scores;     string myLine2;     openFile(inFile, inFileName);     getAvgofContents(inFile, myLine2); }  void openFile(ifstream &file, string name){     file.open(name);      while (!file.is_open()) {         cout << "Unable to open default file/file path.\nPlease enter a new file/file path:" << endl;         cin >> name;         file.open(name);     }     cout << "FILE IS OPEN!!!\n"; }  void getAvgofContents(ifstream &file, string line){     while (file){         getline(file, line);         cout << line << endl;     } }  I am supposed to get results like: 73 81.5 84.1 ... ... Then after averaging each line, push the results to a vector.  

What is the probability to take out 1 blue, at least 1 green after having taken the last red ball, from a box?

My problem is the following. You have a box with 10 red, 20 blue, and 30 green balls. You take out a ball from the box, without returning it. The problem is: What is the probability to take out 1 blue, at least 1 green after having taken the last red ball, from a box?

Which software can take a batch of classified images and automatically learn from them to classify automatically furthe rimages?

I have a Lightroom library that contains some photos I classified myself and some other ones (in both cases, thousands) not yet classified.

I want to automatically classify images based on the tags I assigned to the images I already classified.

Most steps (I use Lightroom) are simple:

  • write XMP files
  • filter the files according to the tags
  • feed each set of images (one set per tag) to a software
  • use the output of the software to write new XMP files
  • instruct Lightroom to reload metadata from XMP files.

However, which (artificial intelligence) software can I use for the purpose?

The question is asked here in Photo because I’m asking about a ready or almost ready package, not about about which software/package to use when programming a new AI.

Why does it take so long when I click on the filename in the window title?

When I click on the filename of e.g. TextEdit, to change the file name and select where it is saved, it always take 1-2 seconds until the selector thingy pops up.

That has always been like that for me. It’s a bit annoying. I don’t think it’s a bug on my system. Maybe I’m wrong.

Why is that interaction so slow?

Does anyone else experience that?

C How to make queue function take packets/items out of queue

I’m trying to make this queue program for school to take the next packet out of my queue (therefore delete it) in the queue function : struct packet_t *queue_retrieve(struct queue_t *queue) in line 73. I know that i have to use my write and read but i fail to understand how exactly.

I also have to implement it as a circular buffer so when it reaches the end of my queue it starts at 0 again. Also is it enough to free(q) and (p) in order to delete packets/queues like i did in the queue_destroy and packet_destroy functions or do i have to add more here?

#include <stdio.h> #include <stdlib.h> #include <time.h> #include <limits.h> #include <string.h>    struct packet_t {     char *name;     struct queue_t *queue; };  struct queue_t {     char *name;     // name of queue     int size;       // size of queue     int entries;    // number of valid entries in queue     int time;       // timestamp (we will need that later in P6)     struct packet_t **packets; // Array of pointer on packets     int read;       // read-position (retrieve_packet())     int write;      // write-Position (store_packet())     long lost;      // number of all lost packets };   struct queue_t *queue_create(char *name, int size) {     int i;     struct queue_t *q;                           /* temporary pointer on queue */     q = malloc(sizeof(struct queue_t));      if (q == NULL) {         printf("Memory allocation failed");         //check for NULL         exit(0);     }      q -> name = name;     q -> size = size;     q -> entries = 0;     q -> write   = 0;     q -> read    = -1;     q -> lost    = 0;      return (q); }   long queue_store(struct queue_t *q, struct packet_t *p) {      int total = 0;      q -> entries ++;     q -> write++;     q -> read++;      p -> name = q -> name;      if (q -> entries < q -> size) {          total ++;          return total;      }     else {         packet_destroy(p);                          // packet gets destroyed not enough space         q -> lost ++;                               // lost packet counter         return 0;     }  }   struct packet_t* queue_retrieve(struct queue_t *q) {     //need help here      struct packet_t *p;      ...     return (p); }  int queue_destroy(struct queue_t *q) {      free (q);                                        // destroys queue and frees memory allocated  }  struct packet_t* packet_create(char *p) {      struct packet_t * packet;      packet = malloc (sizeof(struct packet_t));      packet -> name = p;      return (packet); }   int packet_destroy(struct packet_t *packet) {      // destroys packet and frees memory allocated      free(p);  }    // to test my queue int main(void) {      long i;      struct queue_t *Q;                              // pointer on queue     struct packet_t *P;                             // pointer on packet      clock_t start, ende;      start = clock();      for (i = 0; i < 1000000; i++) {         P = packet_create ("tester");     }     ende = clock();     printf("create packets:\n");     printf("i     = %ld\n", i);     printf("T[s]  = %g\n", (double) (ende - start) / CLOCKS_PER_SEC);     printf("\n");       start = clock();     for (i = 0; i < 1000000; i++) {         Q = queue_create ("test-queue with 100 spaces", 100);     }     ende = clock();      printf("create queues:\n");     printf("i     =%ld\n", i);     printf("T[s]  = %g\n", (double) (ende - start) / CLOCKS_PER_SEC);     printf("\n");         start = clock();      Q = queue_create ("test, 100", 100);      // fill queue halfway     for (i = 0; i < 50; i++) {          P = packet_create ("none");         queue_store (Q,P);     }      // create many packets     for (i = 0; i < 1000000; i++) {         P = packet_create ("none");         queue_store (Q,P);         P=queue_retrieve(Q);         packet_destroy(P);     }      // delete prefill     for (i = 0; i < 50; i++) {         P = queue_retrieve(Q);         packet_destroy(P);     }       ende = clock();      printf("create queues, <create packets, safe,load,destroy>:\n");      printf("i     =%ld\n", i);     printf("T[s]  = %g\n", (double) (ende - start) / CLOCKS_PER_SEC);     printf("\n");         start = clock();      Q = queue_create ("test-queue for 1000 packets", 1000);      for (i = 0; i < 900; i++) {         P = packet_create ("aha");         queue_store (Q,P);      }     for (i = 0; i < 901; i++) {         P=queue_retrieve(Q);         if (NULL == P)             printf ("no packet\n");         else             packet_destroy(P);      }     ende = clock();      printf("create queue, <create packet, safe,load,destroy>:\n");      printf("i     =%ld\n", i);     printf("T[s]  = %g\n", (double) (ende - start) / CLOCKS_PER_SEC);     printf("\n");       start = clock();      Q = queue_create ("test, 1000", 1000);      for (i = 0; i < 900; i++) {         P = packet_create ((int)i,0.0,0L,NULL);         queue_store (Q,P);      }     for (i = 0; i < 450; i++) {         P=queue_retrieve(Q);         if (NULL == P)             printf ("no packet\n");         else             packet_destroy(P);      }     ende = clock();      printf("create queue, <create packet, safe,load,destroy>:\n");      printf("i     =%ld\n", i);     printf ("Q->entries = %d\n", Q->entries);     printf("T[s]  = %g\n", (double) (ende - start) / CLOCKS_PER_SEC);     printf("\n"); } 

Best camera/lens to take photo’s of textures (Tiles/Countertops and other textures.) All for 3D use

I would really appreciate if you could help me find the best camera or camera’s to take photos of textures.

These will mainly include cabinets, countertops, tiles, backsplashes, hardwood flooring and possibly exterior brick walls.

The photos also need to be quite “flat” as it would be used as 3D textures. (I have added two links to examples.)

https://www.google.co.za/search?q=tile+texture&rlz=1C1CHBD_enZA756ZA756&tbm=isch&source=lnt&tbs=isz:lt,islt:2mp&sa=X&ved=0ahUKEwjTjdO67-3fAhXySxUIHQ3NCfgQpwUIIQ&biw=1858&bih=1009&dpr=1#imgrc=XMQsbA8UAyx9kM:

https://www.google.co.za/search?rlz=1C1CHBD_enZA756ZA756&biw=1858&bih=1009&tbs=isz%3Alt%2Cislt%3A2mp&tbm=isch&sa=1&ei=t9A8XImACZ-H1fAPiP-1WA&q=countertop+texture&oq=countertop+texture&gs_l=img.3…178623.179903..180173…0.0..0.391.2932.2-4j5……1….1..gws-wiz-img.NRVYukejWZI#imgrc=0cUeWPd_ID8Z3M:

I have a lightbox setup with an android phone taking photo’s which is not detailed enough and has a slight noise in the image.

Kind regards,

Daniel Herbst

C# how long did it take you to write your first Roslyn Analyzer + CodeFixer

Tl;Dr: Check out the last paragraph

Yeah So I got the feeling that I’m a bit slow at getting to know new APIs. At first I was completely overwhelmed on how to get anything to start at all but I wanted it so bad because I was multiple times confronted with the issue that I could’t inherit static Methods/Properties to collect MetaData that wouldn’t be possible with Attributes. So my Intention is to use those Methods on the Fly and as a Reinterpretation of a given baseClass’ Implementation, like let’s say what’s most important in Life for Millenials vs BabyBoomers. you wouldn’t need this Property for every instance of a class, but every subclass defines this Property itself. Know where I’m heading?

So I wrote an Analyzer that has about 11 Diagnostics and 3 CodeFixes and it took me 3 weeks, starting from Dec 24 (yeah maybe the christmas week shouldn’t count^^).

I remember when I started, I was constantly overwhelmed, didn’t know where to start, scrambled information on Google, found Josh Varty’s tutorials, which are good at giving you a basic orientation, and started to mess around. Do you know this stupid feeling when you think “Geez this is over my head” and your head hurts from the thought of really doing it? It feels like being a caveman that wants to dig a tunnel by smashing his head against the wall. It took me three days to realize that I just have to chill out, play around a bit figure how everything is connected and period. I somehow managed to get the Analyzer done in let’s say 7 Days. And then I realized crap, the Codefixer is just another whole topic. BUt now you can’t just use Symbols, you have to use SyntaxNodes. And you can’t just remove an Attribute or modifier there, or if you can, you better make an Extension Method for it, because it’s messy. (same goes for getting an appropriate DisplayString for symbols). So I felt like having to work with an unintuitive, happy-it-works-API and when I was confronted with those piling nuisances I was really pissed about. But then I had to tell me: alright, you’re just the first one that has the honor to be in need of such functionality.^^ It was a struggle I’m telling ya^^

There were also like Day 13-16 where I just didn’t want to. I was blocked. My head hurt and he begged me, please stop torturing me!^^ And I figured it was that time again when I was about to figure how the pieces fall into place, my backgroundThreads just had to process what I did so far. And yeah then it clicked. It felt like I freaking know how to handle this API now. And in retrospective everything is just so … obvious ๐Ÿ˜€

Of course it has some minor issues now. but it’s working as intended.

The Question is now? Could I have done it in less than 3 weeks? How do you handle stuff you don’t know? how do you cope wth those blockades? how do you keep steady progress? i know those are general questions but I think I should have done that in half the time. NO, I want stuff like that being done in half of the time. DO you have any recommendations? How do you relax from this kind of work to get back fresh? I think I can do so much better but don’t know freaking how. Give me a mentor!^^ Give me your insights. or at least breadcrumbs. I can work with that^^

Thanks and Ciao ๐Ÿ˜‰